diff options
| author | marcin mikołajczak <git@mkljczk.pl> | 2022-08-05 11:53:44 +0200 |
|---|---|---|
| committer | marcin mikołajczak <git@mkljczk.pl> | 2022-08-05 11:53:44 +0200 |
| commit | 6649baaac94348bbf09015eeb2c8eeea714096db (patch) | |
| tree | 6793738e657b087b5f0aa556dc7a82a79e2ccb1f /src/lib/persisted_state.js | |
| parent | 79d02bddbe2b77574844b8ade7a09043c31b1c6b (diff) | |
| parent | 610720f164dc9fcf36f9df33bddec5ac9c654e1e (diff) | |
Merge remote-tracking branch 'pleroma/develop' into birthdays
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
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') { |
