Git Product home page Git Product logo

pinia-persistedstate's People

Contributors

jd-wang avatar tinolee615 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

mawei1191546352

pinia-persistedstate's Issues

Persistence corrupts the stores on refresh (for stores in option.paths)

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']
    })
  )
  1. I'll delete Pinia from the browser local storage. Here's local storage after deleting it.

image

  1. I'll do a CTRL+F5 to force a full refresh.

We now have a legit local storage for Pinia.

image

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.

image

Here's the common store state, which is correct.

image

  1. Now I'll do an F5 to refresh.

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!

image

And so too are the deal and common stores.

image

image

I'm using version 0.1.2 of pinia-persistedstate.

$ npm list pinia-persistedstate

[email protected] C:\development\CRMDealsWebApp
`-- [email protected]

Empty paths array returns (persists) entire state, not no state as docs indicate

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.