Skip to content

Commit

Permalink
fix autoRehydrate, object equality
Browse files Browse the repository at this point in the history
  • Loading branch information
rt2zz committed Oct 24, 2015
1 parent 5484595 commit eec02a7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/autoRehydrate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { compose } from 'redux'
import isPlainObject from 'lodash.isplainobject'
import bufferActions from './bufferActions'
import { REHYDRATE } from './constants'
Expand Down Expand Up @@ -37,19 +36,20 @@ module.exports = function autoRehydrate (config) {
return reducedState
}

var autoReducedState = {...reducedState}
if (!isPlainObject(data) || !isPlainObject(reducedState[key])) {
// substates are not objects -> assign value
reducedState[key] = data
autoReducedState[key] = data
} else {
// substates are objects -> shallow merge
var subState = {}
for (var subkey in reducedState[key]) { subState[subkey] = reducedState[key][subkey] }
for (var datakey in data) { subState[datakey] = data[datakey] }
reducedState[key] = subState
autoReducedState[key] = subState
}

if (config.log) { console.log('redux-persist/autoRehydrate key: %s, rehydrated to:', key, subState) }
return reducedState
if (config.log) { console.log('redux-persist/autoRehydrate key: %s, rehydrated to:', key, autoReducedState[key]) }
return autoReducedState
} else {
return reducer(state, action)
}
Expand Down

0 comments on commit eec02a7

Please sign in to comment.