davestewart / vuex-pathify

Vue / Vuex plugin providing a unified path syntax to Vuex stores
https://davestewart.github.io/vuex-pathify
MIT License
1.37k stars 57 forks source link

Sync doesn't work with dynamic modules registered w/ Vuex's registerModule #74

Closed JessicaSachs closed 5 years ago

JessicaSachs commented 5 years ago

When I use dynamic modules, sync breaks. :-(

Here's the example repo... And here's the line that I think should be working but isn't.

A short example, assuming that the store is properly implemented, looks like this:

export default {
    computed: {
        foo: get('topLevel/myDynamicModule/foo'), // works
        // foo: sync('topLevel/myDynamicModule/foo'), // broken
    },
    beforeCreate() { this.$store.registerModule('topLevel/myDynamicModule', MyDynamicStore); }
}
davestewart commented 5 years ago

Cool - so had a quick look at this, just to verify.

I checked to see if the latest updates caused this, but it looks like 1.2 shows the same behaviour.

At work today, so I'll dive in when I get home later.

davestewart commented 5 years ago

Just read my own docs again, and I think this might already be solved.

Did you read this section?

Pathify's registerModule() helper is designed to:

  • register a store module via component beforeCreate
  • add or extend the component's computed properties with new ones
  • add or extend the component's methods with new ones
  • unregister a store module via component destroyed

Its signature is similar to Vuex.registerModule() with the addition of a callback that should return new component blocks. It is implemented as a function which returns an object which can used as a base class or mixin.

I realise there is a lot to read, because I try to explain everything 😬

It might be that I need to add a higher-level heading / section or page for this more-advanced stuff.

JessicaSachs commented 5 years ago

Ah, this seems to have fixed it! Thank you.