Open scriptPilot opened 6 years ago
Something like this?
export default function (key = 'vuex') {
function getState (key) {
return new Promise((resolve, reject) => {
NativeStorage.getItem(key, resolve, reject)
})
}
function setState (key, state) {
return new Promise((resolve, reject) => {
NativeStorage.setItem(key, state, resolve, reject)
})
}
return function (store) {
getState(key).then(state => {
if (typeof state === 'object') {
const merged = Object.assign({}, store.state, savedState)
store.replaceState(merged)
}
})
store.subscribe((mutation, state) => setState(key, state))
}
}
State management: https://vuex.vuejs.org/en/ Keep state: https://github.com/robinvdvleuten/vuex-persistedstate Native storage: https://github.com/TheCocoaProject/cordova-plugin-nativestorage