michaelolof / vuex-class-component

A Type Safe Vuex Module or Store Using ES6 Classes and ES7 Decorators written in TypeScript.
217 stars 21 forks source link

[Bug] Internal mutator of namespaced SUB modules not working #55

Closed SaphuA closed 4 years ago

SaphuA commented 5 years ago

It seems like there's an issue when a namespace is applied to submodules. Those without namespaces work, but naming collisions are quite annoying so I'd rather have namespaces. It seems that the module is correctly registered with a namespace, but the internals are probably not taking the namespaces into account.

I've updated my previous repo: https://github.com/SaphuA/vuex-class-component-ns-repro The error is in store.ts: https://github.com/SaphuA/vuex-class-component-ns-repro/blob/master/src/store.ts#L42

Sorry to bring you only bad news all the time ;)

SaphuA commented 5 years ago

Seems like the tests in create-proxy.spec.ts are already failing because of this.

tiagoroldao commented 5 years ago

Is this currently not true for ANY namespaced module (root or submodule)? I'm seeing this exact issue on latest, on namespaced modules (not submodules). It appears the mutation is named globally, but called locally (using module commit, rather than store.$commit)

jamesmarnoch commented 4 years ago

I've run into this issue, and have a workaround:

Name your namespaced submodule field to be the same as the class: subN -> SubStoreN

this fixes your repro

My further issue is if an action on a store is mutating state on that store, I get a similar error.

My workaround is to change:

if (commit)
   commit(utils_1.refineNamespacedPath(cls.prototype.__namespacedPath__) + ("__" + className + "_internal_mutator__"), { field: path, payload: payload });

to

if (commit)
   commit(utils_1.refineNamespacedPath(cls.prototype.__namespacedPath__) + ("__" + className + "_internal_mutator__"), { field: path, payload: payload }, {root: true);

in Proxy.js I'm not sure this is "the right way" to do this, it just got me past this issue, for now

HTH

tiagoroldao commented 4 years ago

[Edited to update dependency to latest fixes] I have a PR for this fix up. In the meantime, I've been using my fork of the lib, by targeting a built commit, as such:

// package.lock dependencies
...
"vuex-class-component": "git+https://github.com/tiagoroldao/vuex-class-component.git#f71e27bc4960607081a936c3a756915656af520b",
...
SaphuA commented 4 years ago

I have had great sucess with an alternative library which is still maintained, perhaps it is of interest to people https://github.com/paleo/direct-vuex

tiagoroldao commented 4 years ago

Cheers @SaphuA 😄