Giter Site home page Giter Site logo

Comments (6)

maoberlehner avatar maoberlehner commented on August 27, 2024

Hey @alsconsulting there are some quirks with persistedState and dynamically registered modules, but you can checkout this issue: robinvdvleuten/vuex-persistedstate#100

Please let me know if this works for you. Thx.

from how-to-structure-a-complex-vuex-store.

alsconsulting avatar alsconsulting commented on August 27, 2024

from how-to-structure-a-complex-vuex-store.

maoberlehner avatar maoberlehner commented on August 27, 2024

Hmm, I understand that this is a frustrating situation. But I don't see what I can do about it. The technique described in my blog article and featured in this repository, works as it is.

As I see it, it's a problem with the vuex-persistedstate package. I'd suggest to make your case in the issue I've linked above.

Thx.

from how-to-structure-a-complex-vuex-store.

alsconsulting avatar alsconsulting commented on August 27, 2024

Ended up declaring and instantiating everything at the root level. Seemed to be a mixture of the dynamic registering and trying to use three levels. Ie. Module within a module.

from how-to-structure-a-complex-vuex-store.

maoberlehner avatar maoberlehner commented on August 27, 2024

Hey @alsconsulting

I'm sorry, I completely misunderstood the problem. I took a closer look and I realized it's not a problem with the vuex-persistedstate package at all, but with how I check if the module was already registered. Unfortunately there is no "clean" way of how to check if a module was already registered, so the way I solved it, is a little hacky (more about that problem: vuejs/vuex#833).

This is what I've done to make it work: 9018a9b

const shippingAddressModuleRegistered = store._modules.root._children.shippingAddress !== undefined;
const shippingAddressStateExists = store.state.shippingAddress;

// Previously I've checked if the state was set to determine if the component was registered
// but with persistedstate, the state is set although the component is not registered yet.
// The new method above, checks if the module is registered for real.
if (!shippingAddressModuleRegistered) {
  // The preserveState option is only set to true, if there already is a state to preserve.
  // So for the first time the page is loaded, there is no state and we set the
  // preserveState option to `false` on further page loads, the persistedState kicks in,
  // so there already is a state and we set preserveState to `true`.
  store.registerModule(`shippingAddress`, shippingAddress, { preserveState: shippingAddressStateExists });
}

from how-to-structure-a-complex-vuex-store.

maoberlehner avatar maoberlehner commented on August 27, 2024

You can checkout the feature/vuex-persisted-state branch to see it work with vuex-persistedstate. Thanks for your patience and for raising this issue. I'm happy this problem is solved.

from how-to-structure-a-complex-vuex-store.

Related Issues (4)

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.