-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
91 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
export interface Config<T> { | ||
/** | ||
* Function that gets executed on a storage error (get/set) | ||
* @param error the error that occurred | ||
*/ | ||
error: (error: any) => void | ||
|
||
/** | ||
* Serializer for the state, by default it uses `JSON.stringify()` | ||
* @param state the last state known before it gets saved to storage | ||
*/ | ||
serialize: (state: T) => string | ||
|
||
/** | ||
* Deserializer for the state, by default it uses `JSON.parse()` | ||
* @param state the last state known from the storage location | ||
*/ | ||
deserialize: (state: string) => T | ||
|
||
/** | ||
* Save to storage will only occur when this function returns true | ||
* @param state the last state known before it gets saved to storage | ||
*/ | ||
shouldSave: (state: T) => boolean | ||
} | ||
|
||
export const defaultConfig: Config<any> = { | ||
error: (error: any) => {}, | ||
|
||
serialize: (state: any) => JSON.stringify(state), | ||
|
||
deserialize: (state: string) => JSON.parse(state), | ||
|
||
shouldSave: (state: any) => true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { withStorage } from './lib/with-storage' | ||
export { type Config } from './lib/config' |