Skip to content

Commit

Permalink
(persistReducer): update persistoid on rehydrate (#688)
Browse files Browse the repository at this point in the history
* (persistReducer): update persistoid on rehydrate

* Update persistReducer.js
  • Loading branch information
rt2zz authored Feb 1, 2018
1 parent 21cbb5e commit f89d60b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/persistReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ export default function persistReducer<State: Object, Action: Object>(
let _persistoid = null
let _purge = false
let _paused = true
const conditionalUpdate = state => {
state._persist.rehydrated &&
_persistoid &&
!_paused &&
_persistoid.update(state)
return state
}

return (state: State, action: Action) => {
let { _persist, ...rest } = state || {}
Expand Down Expand Up @@ -129,10 +136,11 @@ export default function persistReducer<State: Object, Action: Object>(
? stateReconciler(inboundState, state, reducedState, config)
: reducedState

return {
let newState = {
...reconciledRest,
_persist: { ..._persist, rehydrated: true },
}
return conditionalUpdate(newState)
}
}

Expand All @@ -146,10 +154,6 @@ export default function persistReducer<State: Object, Action: Object>(
_persist,
}
// update the persistoid only if we are already rehydrated and are not paused
_persist.rehydrated &&
_persistoid &&
!_paused &&
_persistoid.update(newState)
return newState
return conditionalUpdate(newState)
}
}

0 comments on commit f89d60b

Please sign in to comment.