Skip to content

Instantly share code, notes, and snippets.

@qkreltms
Created April 18, 2021 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qkreltms/ad7991302eaf5fc55502c086875a0d1a to your computer and use it in GitHub Desktop.
Save qkreltms/ad7991302eaf5fc55502c086875a0d1a to your computer and use it in GitHub Desktop.
 } else if (action.type === REHYDRATE) {
      // noop on restState if purging
      if (_purge)
        return {
          ...restState,
          _persist: { ..._persist, rehydrated: true },
        }

      // @NOTE if key does not match, will continue to default else below
      if (action.key === config.key) {
        let reducedState = baseReducer(restState, action)
        let inboundState = action.payload
        // only reconcile state if stateReconciler and inboundState are both defined
        let reconciledRest: State =
          stateReconciler !== false && inboundState !== undefined
            ? stateReconciler(inboundState, state, reducedState, config)
            : reducedState

        let newState = {
          ...reconciledRest,
          _persist: { ..._persist, rehydrated: true },
        }
        return conditionalUpdate(newState)
      }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment