Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85833069
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/lib/persisted_state.js b/src/lib/persisted_state.js
index a47ad7d59b..26a9d0e4da 100644
--- a/src/lib/persisted_state.js
+++ b/src/lib/persisted_state.js
@@ -1,58 +1,65 @@
import merge from 'lodash.merge'
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))
return substate
}, {})
)
const defaultStorage = (() => {
return localforage
})()
const defaultSetState = (key, state, storage) => {
- return storage.setItem(key, state)
+ if (!loaded) {
+ console.log('waiting for old state to be loaded...')
+ } else {
+ return storage.setItem(key, state)
+ }
}
export default function createPersistedState ({
key = 'vuex-lz',
paths = [],
getState = (key, storage) => {
let value = storage.getItem(key)
return value
},
setState = throttle(defaultSetState, 60000),
reducer = defaultReducer,
storage = defaultStorage,
subscriber = store => handler => store.subscribe(handler)
} = {}) {
return store => {
getState(key, storage).then((savedState) => {
if (typeof savedState === 'object') {
// build user cache
const usersState = savedState.users || {}
usersState.usersObject = {}
const users = usersState.users || []
each(users, (user) => { usersState.usersObject[user.id] = user })
savedState.users = usersState
store.replaceState(
merge({}, store.state, savedState)
)
}
+ loaded = true
})
subscriber(store)((mutation, state) => {
try {
setState(key, reducer(state, paths), storage)
} catch (e) {
console.log("Couldn't persist state:")
console.log(e)
}
})
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Nov 2, 9:52 AM (1 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1804325
Default Alt Text
(1 KB)
Attached To
Mode
rPUFE pleroma-fe-upstream
Attached
Detach File
Event Timeline