Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/createPersistoid.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export default function createPersistoid(config: PersistConfig): Persistoid {
const whitelist: ?Array<string> = config.whitelist || null
const transforms = config.transforms || []
const throttle = config.throttle || 0
const storageKey = `${config.keyPrefix !== undefined
? config.keyPrefix
: KEY_PREFIX}${config.key}`
const storageKey = `${
config.keyPrefix !== undefined ? config.keyPrefix : KEY_PREFIX
}${config.key}`
const storage = config.storage
const serialize = config.serialize === false ? x => x : defaultSerialize

Expand Down Expand Up @@ -50,7 +50,7 @@ export default function createPersistoid(config: PersistConfig): Persistoid {

let key = keysToProcess.shift()
let endState = transforms.reduce((subState, transformer) => {
return transformer.in(subState, key)
return transformer.in(subState, key, lastState)
}, lastState[key])
if (typeof endState !== 'undefined') stagedWrite(key, endState)
}
Expand Down Expand Up @@ -79,7 +79,8 @@ export default function createPersistoid(config: PersistConfig): Persistoid {
}

function passWhitelistBlacklist(key) {
if (whitelist && whitelist.indexOf(key) === -1 && key !== '_persist') return false
if (whitelist && whitelist.indexOf(key) === -1 && key !== '_persist')
return false
if (blacklist && blacklist.indexOf(key) !== -1) return false
return true
}
Expand Down
12 changes: 8 additions & 4 deletions src/createTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ export default function createTransform(
}

return {
in: (state: Object, key: string) =>
!whitelistBlacklistCheck(key) && inbound ? inbound(state, key) : state,
out: (state: Object, key: string) =>
!whitelistBlacklistCheck(key) && outbound ? outbound(state, key) : state,
in: (state: Object, key: string, fullState: Object) =>
!whitelistBlacklistCheck(key) && inbound
? inbound(state, key, fullState)
: state,
out: (state: Object, key: string, fullState: Object) =>
!whitelistBlacklistCheck(key) && outbound
? outbound(state, key, fullState)
: state,
}
}
8 changes: 4 additions & 4 deletions src/getStoredState.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export default function getStoredState(
config: PersistConfig
): Promise<Object | void> {
const transforms = config.transforms || []
const storageKey = `${config.keyPrefix !== undefined
? config.keyPrefix
: KEY_PREFIX}${config.key}`
const storageKey = `${
config.keyPrefix !== undefined ? config.keyPrefix : KEY_PREFIX
}${config.key}`
const storage = config.storage
const debug = config.debug
const deserialize = config.serialize === false ? x => x : defaultDeserialize
Expand All @@ -22,7 +22,7 @@ export default function getStoredState(
let rawState = deserialize(serialized)
Object.keys(rawState).forEach(key => {
state[key] = transforms.reduceRight((subState, transformer) => {
return transformer.out(subState, key)
return transformer.out(subState, key, rawState)
}, deserialize(rawState[key]))
})
return state
Expand Down
4 changes: 2 additions & 2 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export type MigrationManifest = {
}

export type Transform = {
in: (Object | string, string) => Object,
out: (Object | string, string) => Object,
in: (Object | string, string, Object | string) => Object,
out: (Object | string, string, Object | string) => Object,
config?: PersistConfig,
}

Expand Down