Skip to content

Commit

Permalink
add static method to clear all data
Browse files Browse the repository at this point in the history
This creates a temporary fix for issues using split type with
react.
  • Loading branch information
lukePeavey committed Oct 22, 2023
1 parent 808e62f commit 4c78aaf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/Data.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ export function remove(element) {
}
}

/**
* Clear all cached data
*/
export function clear() {
Object.keys(cache).forEach((key) => {
delete cache[key]
})
}

/**
* Remove all temporary data from the store.
*/
Expand Down
7 changes: 7 additions & 0 deletions lib/SplitType.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ export default class SplitType {
return data.cache
}

/**
* CLears all data
*/
static clearData() {
data.clear()
}

/**
* The default settings for all splitType instances
* @static
Expand Down
10 changes: 10 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ declare module 'split-type' {
*/
chars: HTMLElement[] | null

/**
* Returns the data store object. This is mainly for debugging purposes.
*
*/
static data: any

/**
* Removes all data from the cache.
*/
static clearData (): void
/**
* Get the default settings for all SplitType calls, or set new ones.
*
Expand Down

0 comments on commit 4c78aaf

Please sign in to comment.