Set state to loaded if it crashes while loading.

This commit is contained in:
Roger Braun 2017-04-09 22:15:35 +02:00
parent 1ea19dcf1d
commit 40b607bdea

View file

@ -38,19 +38,24 @@ export default function createPersistedState ({
} = {}) { } = {}) {
return store => { return store => {
getState(key, storage).then((savedState) => { getState(key, storage).then((savedState) => {
if (typeof savedState === 'object') { try {
// build user cache if (typeof savedState === 'object') {
const usersState = savedState.users || {} // build user cache
usersState.usersObject = {} const usersState = savedState.users || {}
const users = usersState.users || [] usersState.usersObject = {}
each(users, (user) => { usersState.usersObject[user.id] = user }) const users = usersState.users || []
savedState.users = usersState each(users, (user) => { usersState.usersObject[user.id] = user })
savedState.users = usersState
store.replaceState( store.replaceState(
merge({}, store.state, savedState) merge({}, store.state, savedState)
) )
}
loaded = true
} catch (e) {
console.log("Couldn't load state")
loaded = true
} }
loaded = true
}) })
subscriber(store)((mutation, state) => { subscriber(store)((mutation, state) => {