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