123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import type { PersistConfig } from '../types'
- export default function autoMergeLevel2<State: Object>(
- inboundState: State,
- originalState: State,
- reducedState: State,
- { debug }: PersistConfig
- ): State {
- let newState = { ...reducedState }
-
- if (inboundState && typeof inboundState === 'object') {
- Object.keys(inboundState).forEach(key => {
-
- if (key === '_persist') return
-
- if (originalState[key] !== reducedState[key]) {
- if (process.env.NODE_ENV !== 'production' && debug)
- console.log(
- 'redux-persist/stateReconciler: sub state for key `%s` modified, skipping.',
- key
- )
- return
- }
- if (isPlainEnoughObject(reducedState[key])) {
-
- newState[key] = { ...newState[key], ...inboundState[key] }
- return
- }
-
- newState[key] = inboundState[key]
- })
- }
- if (
- process.env.NODE_ENV !== 'production' &&
- debug &&
- inboundState &&
- typeof inboundState === 'object'
- )
- console.log(
- `redux-persist/stateReconciler: rehydrated keys '${Object.keys(
- inboundState
- ).join(', ')}'`
- )
- return newState
- }
- function isPlainEnoughObject(o) {
- return o !== null && !Array.isArray(o) && typeof o === 'object'
- }
|