Skip to content

Commit

Permalink
add config.serialize as boolean (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
rt2zz authored Nov 16, 2016
1 parent 19c96cd commit 1786899
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion redux-persist.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ declare module 'redux-persist' {
storage?: Storage,
transforms?: Array<Object>,
debounce?: number,
serialize?: boolean,
}
declare type Purge = (keys: Array<string>) => void
declare type Rehydrate = (incoming: Object, options: { serial: boolean }) => void
Expand All @@ -31,7 +32,7 @@ declare module 'redux-persist' {
resume: () => void,
}
declare type OnComplete = (err?: any, result?: Object) => void

declare type AutoRehydrate = Function
declare type CreatePersistor = (store: Store, config: Config) => Persistor
declare type CreateTransform = (in: TransformIn, out: TransformOut, config: TransformConfig) => Transform
Expand Down
12 changes: 6 additions & 6 deletions src/createPersistor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import stringify from 'json-stringify-safe'

export default function createPersistor (store, config) {
// defaults
const serialize = config.serialize || defaultSerialize
const deserialize = config.deserialize || defaultDeserialize
const serializer = config.serialize === false ? (data) => data : defaultSerializer
const deserializer = config.serialize === false ? (data) => data : defaultDeserializer
const blacklist = config.blacklist || []
const whitelist = config.whitelist || false
const transforms = config.transforms || []
Expand Down Expand Up @@ -55,7 +55,7 @@ export default function createPersistor (store, config) {
let key = storesToProcess[0]
let storageKey = createStorageKey(key)
let endState = transforms.reduce((subState, transformer) => transformer.in(subState, key), stateGetter(store.getState(), key))
if (typeof endState !== 'undefined') storage.setItem(storageKey, serialize(endState), warnIfSetError(key))
if (typeof endState !== 'undefined') storage.setItem(storageKey, serializer(endState), warnIfSetError(key))
storesToProcess.shift()
}, debounce)
}
Expand All @@ -74,7 +74,7 @@ export default function createPersistor (store, config) {
if (options.serial) {
stateIterator(incoming, (subState, key) => {
try {
let data = deserialize(subState)
let data = deserializer(subState)
let value = transforms.reduceRight((interState, transformer) => {
return transformer.out(interState, key)
}, data)
Expand Down Expand Up @@ -108,7 +108,7 @@ function warnIfSetError (key) {
}
}

function defaultSerialize (data) {
function defaultSerializer (data) {
return stringify(data, null, null, (k, v) => {
if (process.env.NODE_ENV !== 'production') return null
throw new Error(`
Expand All @@ -120,7 +120,7 @@ function defaultSerialize (data) {
})
}

function defaultDeserialize (serial) {
function defaultDeserializer (serial) {
return JSON.parse(serial)
}

Expand Down

0 comments on commit 1786899

Please sign in to comment.