forked from AkkomaGang/akkoma-fe
Set state to loaded if it crashes while loading.
This commit is contained in:
parent
1ea19dcf1d
commit
40b607bdea
1 changed files with 16 additions and 11 deletions
|
@ -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) => {
|
||||||
|
|
Loading…
Reference in a new issue