pinia-plugin-persistedstate icon indicating copy to clipboard operation
pinia-plugin-persistedstate copied to clipboard

[core] feat: Take the value of Paths only the final layer

Open yucccc opened this issue 2 years ago • 8 comments

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

image

But I just want to get the following format:

  totalResData: {
    // ...my data
  }

Suggested solution

image

Add a parameter to make it go directly to the final level

Then I can get such data

image

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.

yucccc avatar Jul 31 '22 14:07 yucccc

Mmmh I don't really understand what you are trying to achieve, can you be more explicit and give detailed examples ? thanks :)

prazdevs avatar Jul 31 '22 14:07 prazdevs

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 ?

prazdevs avatar Jul 31 '22 15:07 prazdevs

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.

yucccc avatar Jul 31 '22 15:07 yucccc

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

yucccc avatar Jul 31 '22 15:07 yucccc

so you want totalResData: { // ...my data } to be in the storage (localstorage for instance) instand of the whole tree right ?

prazdevs avatar Jul 31 '22 17:07 prazdevs

yes !

yucccc avatar Aug 01 '22 01:08 yucccc

@prazdevs what he need is not simple flatten。 he need such

paths: [{ statePath: 'page.totalResData', storagePath: 'totalResData' }]
// or
paths: [['page.totalResData', 'totalResData']]

wxhccc avatar Aug 01 '22 08:08 wxhccc

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

prazdevs avatar Aug 01 '22 11:08 prazdevs

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

prazdevs avatar Nov 26 '22 01:11 prazdevs