forked from AkkomaGang/akkoma-fe
Only persist state after we loaded one.
This commit is contained in:
parent
a53555254a
commit
e531c78079
1 changed files with 8 additions and 1 deletions
|
@ -3,6 +3,8 @@ import objectPath from 'object-path'
|
|||
import localforage from 'localforage'
|
||||
import { throttle, each } from 'lodash'
|
||||
|
||||
let loaded = false
|
||||
|
||||
const defaultReducer = (state, paths) => (
|
||||
paths.length === 0 ? state : paths.reduce((substate, path) => {
|
||||
objectPath.set(substate, path, objectPath.get(state, path))
|
||||
|
@ -15,8 +17,12 @@ const defaultStorage = (() => {
|
|||
})()
|
||||
|
||||
const defaultSetState = (key, state, storage) => {
|
||||
if (!loaded) {
|
||||
console.log('waiting for old state to be loaded...')
|
||||
} else {
|
||||
return storage.setItem(key, state)
|
||||
}
|
||||
}
|
||||
|
||||
export default function createPersistedState ({
|
||||
key = 'vuex-lz',
|
||||
|
@ -44,6 +50,7 @@ export default function createPersistedState ({
|
|||
merge({}, store.state, savedState)
|
||||
)
|
||||
}
|
||||
loaded = true
|
||||
})
|
||||
|
||||
subscriber(store)((mutation, state) => {
|
||||
|
|
Loading…
Reference in a new issue