Skip to content

Commit

Permalink
add customizing serializer/deserializer config
Browse files Browse the repository at this point in the history
  • Loading branch information
scott1028 committed Jan 3, 2019
1 parent 1a46791 commit a94f291
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/createPersistoid.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export default function createPersistoid(config: PersistConfig): Persistoid {
config.keyPrefix !== undefined ? config.keyPrefix : KEY_PREFIX
}${config.key}`
const storage = config.storage
const serialize = config.serialize === false ? x => x : defaultSerialize
let serialize = config.serialize === false ? x => x : defaultSerialize
if (typeof config.serialize === 'function') {
serialize = config.serialize
}
const writeFailHandler = config.writeFailHandler || null

// initialize stateful values
Expand Down
5 changes: 4 additions & 1 deletion src/getStoredState.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export default function getStoredState(
}${config.key}`
const storage = config.storage
const debug = config.debug
const deserialize = config.serialize === false ? x => x : defaultDeserialize
let deserialize = config.serialize === false ? x => x : defaultDeserialize
if (typeof config.deserialize === 'function') {
deserialize = config.deserialize
}
return storage.getItem(storageKey).then(serialized => {
if (!serialized) return undefined
else {
Expand Down
3 changes: 2 additions & 1 deletion src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export type PersistConfig = {
stateReconciler?: false | Function,
getStoredState?: PersistConfig => Promise<PersistedState>, // used for migrations
debug?: boolean,
serialize?: boolean,
serialize?: boolean | Function,
deserialize?: Function | null,
timeout?: number,
writeFailHandler?: Function,
}
Expand Down

0 comments on commit a94f291

Please sign in to comment.