Closed
Description
Why not have state storage automatically integrated with Vuex? The way I was thinking of specifying it was like this:
// cart.js
export default {
state: {
items: [],
status: 'ok'
},
mutations: { ... },
save: ['items', 'status'] || { all: true }
}
Overriding the default storage provider:
// save-override.js
export default {
load(module, property) { // invoked on page load
return JSON.parse(localStorage.getItem(`${module}.${property}`))
},
save(state, module, property) {
localStorage.saveItem(`${module}.${property}`, state[module][property])
}
}
Saving through a middleware feels clunky somehow, like it doesn't fit with this specific purpose. A default storage implementation can be provided so only 1-liners are needed to enable saving/loading.
Metadata
Metadata
Assignees
Labels
No labels