pinia-plugin-persistedstate
pinia-plugin-persistedstate copied to clipboard
[core] feat: Take the value of Paths only the final layer
Clear and concise description of the problem
Now set the value obtained by Paths and the path is too long. I only want the data at the bottom layer. What should I do?
persist: {
paths: ['page.totalResData'],
}
get
But I just want to get the following format:
totalResData: {
// ...my data
}
Suggested solution
Add a parameter to make it go directly to the final level
Then I can get such data
My English is not good, forgive me
Alternative
No response
Additional context
No response
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guide.
- [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Mmmh I don't really understand what you are trying to achieve, can you be more explicit and give detailed examples ? thanks :)
Dont worry about english, as long as we understand what you need and can work it out 💪
I just don't understand the "I only want the data at the bottom layer." part. Are we trying to flatten everything under "totalResData" ?
I can somehow see what is behind this with the "flatten" but flatten is usually made with Arrays and not objects ?
Mmmh I don't really understand what you are trying to achieve, can you be more explicit and give detailed examples ? thanks :)
Because our logic for saving code is multiple sets, and the logic for fetching data is unified, which means that the data fields saved between multiple platforms should be consistent, but now other platforms save data at the final level, and use this plugin to save data It is the original level data, which will cause other platforms to fetch data and report errors.
Flatten
parameter is just an example
I only expect to get the final data according to the paths I set, without the original hierarchical relationship of the store
I don’t know if I described it clearly if my problem
so you want totalResData: { // ...my data }
to be in the storage (localstorage for instance) instand of the whole tree right ?
yes !
@prazdevs what he need is not simple flatten。 he need such
paths: [{ statePath: 'page.totalResData', storagePath: 'totalResData' }]
// or
paths: [['page.totalResData', 'totalResData']]
ye i think i get the idea, i'll see if i can work on a recipe to make it work with current plugin, or if we can implement something to allow it
given how the plugin is and how simple it has to stay, this will no be implemented. however you can still implement this "flatten" style method in your own storage.setItem / storage.getItem