vuex-module-decorators
vuex-module-decorators copied to clipboard
Modules inheritance
When I try to extend module B from module A, I get state of A
@Module
class Collection extends VuexModule {
url = "/collection";
items = [];
}
@Module({ namespaced: true, name: 'owners' })
class Owners extends Collection {
url = "/owners";
}
In this case Collection
is abstract class for another modules. And Owner
will have url /collection
, that is not correct
So, I discovered deeper and figured out this line doesn't not call: https://github.com/championswimmer/vuex-module-decorators/blob/a57bb0c767616846d4b31f6d2fea229b85c00167/src/module/index.ts#L18 Because parent already have state.
Therefore i removed @Module
notation from Collection
class and it works as expected.
But! What if I need to inherit module from another module?
I have been trying to figure out inheritance myself since I am starting to have a lot of virtually identical modules and I need to move a lot of functions to a higher level abstract class. It doesn't seem to be possible :(
Same issue here. Inheritance works, but sometimes it does'nt.
For example, at some point in my application's life cycle I can use the inherited action, but at other times I get the error: [vuex] unknown action type: module/action
I can confirm this, inheritance is broken, also for getters and attributes.
@seflue well, it's possible to fix, I have library for Vuex decorators with ability to inherit state, getters, mutations and actions. But now it's in closed repo, so I can't share right now, unfortunately. I haven't been coding with vue for about half year, so maybe no progress there for a while. But you can try MobX or my own library Storm if it can solve your problem.
Not much value in this lib if inheritance is broken. Pull request with fix is coming up on 2 years old. Alternative: https://vuejsdevelopers.com/2020/10/05/composition-api-vuex/