diff options
Diffstat (limited to 'src/lib/persisted_state.js')
| -rw-r--r-- | src/lib/persisted_state.js | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/lib/persisted_state.js b/src/lib/persisted_state.js index 8ecb66a8..c73a38ec 100644 --- a/src/lib/persisted_state.js +++ b/src/lib/persisted_state.js @@ -1,14 +1,16 @@ import merge from 'lodash.merge' import localforage from 'localforage' -import { each, get, set } from 'lodash' +import { each, get, set, cloneDeep } from 'lodash' let loaded = false const defaultReducer = (state, paths) => ( - paths.length === 0 ? state : paths.reduce((substate, path) => { - set(substate, path, get(state, path)) - return substate - }, {}) + paths.length === 0 + ? state + : paths.reduce((substate, path) => { + set(substate, path, get(state, path)) + return substate + }, {}) ) const saveImmedeatelyActions = [ @@ -30,7 +32,7 @@ export default function createPersistedState ({ key = 'vuex-lz', paths = [], getState = (key, storage) => { - let value = storage.getItem(key) + const value = storage.getItem(key) return value }, setState = (key, state, storage) => { @@ -69,7 +71,7 @@ export default function createPersistedState ({ subscriber(store)((mutation, state) => { try { if (saveImmedeatelyActions.includes(mutation.type)) { - setState(key, reducer(state, paths), storage) + setState(key, reducer(cloneDeep(state), paths), storage) .then(success => { if (typeof success !== 'undefined') { if (mutation.type === 'setOption' || mutation.type === 'setCurrentUser') { |
