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

[core] Add excluded paths option

Open bisubus opened this issue 3 years ago • 4 comments

Clear and concise description of the problem

The suggestion is to add an option to exclude paths. This allows for more fine-grained persistence without requiring to change store structure:

persist: [{
  key: 'foo-unsecure',
  paths: ['foo'],
  excludedPaths: ['foo.bar', 'foo.baz'],
  storage: localStorage
}, {
  key: 'foo',
  paths: ['foo.bar', 'foo.baz'],
  storage: sessionStorage
}]

Suggested solution

            let toStore = state;

            if (paths?.length) {
              toStore = pick(toStore, ...paths);
            }

            if (excludedPaths?.length) {
              toStore = omit(toStore, ...excludedPaths);
            }

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.

bisubus avatar Aug 20 '22 11:08 bisubus

Hi, this is a fairly easy enhancement that can be considered! I'll try to do it asap :)

prazdevs avatar Sep 01 '22 13:09 prazdevs

Happy to do this, if the issue is still open for assignment?

marktlinn avatar May 27 '23 22:05 marktlinn

Hi @marktlinn it still is, the requirements are to use no external libraries, and keep the code as small and readable as possible 😄

prazdevs avatar May 27 '23 23:05 prazdevs