im using vue-persistedstate with specific modules to be set persisted only, and it's working well using path attribute.
but when i try to mix it with reducer, the modules set in the path is not working anymore and reducer set all modules persisted. how should i do with reducer?
const persistedstate = new createPersistedState({
key: "newsportal-vuex",
storage: window.localStorage,
paths: ["auth", "venues", "play", "playWS", "purchaseSettings"], // only the persisted ones
reducer(val) {
if (!localStorage.getItem("newsportal_isuseracceptcookie")) {
// DONT USE PERSISTEDSTATE IF USER DECLINE COOKIES
return {};
}
return val; // <-this return ALL MODULES. i want to set only modules in path
}
});
thanks in advance
just realised i need to rebuild the object
reducer(val, paths) {
if (!localStorage.getItem("newsportal_isuseracceptcookie")) {
// DONT USE PERSISTEDSTATE IF USER DECLINE COOKIES
return {};
}
// make persisted state as in paths
let reducer = {};
Object.entries(val).forEach(entry => {
const [key, value] = entry;
if (paths.includes(key)) {
reducer[key] = value;
}
});
return reducer;
}