jd-wang / pinia-persistedstate Goto Github PK
View Code? Open in Web Editor NEWPersist and rehydrate your Pinia state between page reloads. frok from [vuex-persistedstate](https://github.com/robinvdvleuten/vuex-persistedstate)
Persist and rehydrate your Pinia state between page reloads. frok from [vuex-persistedstate](https://github.com/robinvdvleuten/vuex-persistedstate)
When rehydrating/merging the persisted data for the stores it is corrupting the local storage and store. I have 3 stores named common, crm-dashboard, and deal. We are configured to only persist common and deal.stages.
Here's my config:
store.use(
persistedstate({
overwrite: true,
paths: ['common', 'deal.stages']
})
)
We now have a legit local storage for Pinia.
That all looks correct. It contains only the things we've configured (via option.paths) to persist.
Likewise, the Pinia store looks correct using the Chrome Vue extension.
Here's the deal store state, which is correct.
Here's the common store state, which is correct.
The first indication of trouble is that local storage is now corrupted. Notice that nested in the common store are the common and deal stores!
And so too are the deal and common stores.
I'm using version 0.1.2 of pinia-persistedstate.
$ npm list pinia-persistedstate
[email protected] C:\development\CRMDealsWebApp
`-- [email protected]
From the doc:
paths : An array of any paths to partially persist the state. If no paths are given, the complete state is persisted. If an empty array is given, no state is persisted.
Yet the code returns the entire state if the paths array is empty.
function reducer(state, paths: Array<string>) {
return isNotEmptyArray(paths)
? paths.reduce(function (substate, path) {
return shvl.set(substate, `${path}`, shvl.get(state, path))
}, {})
: state
}
Additionally, I'm not sure enough distinction is made between persisting (to local) storage vs loading/observing? I might be wrong about that though. I say this because stuff is persisted to local storage that I don't think should be based on when I have provided paths so wondering if everything in the store gets persisted to local storage but then gets pruned via reducer on load? So it IS persisted, just reduced back out on load maybe?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.