vuex-module-decorators icon indicating copy to clipboard operation
vuex-module-decorators copied to clipboard

Modules inheritance

Open Disorrder opened this issue 5 years ago • 5 comments

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?

Disorrder avatar May 20 '19 22:05 Disorrder

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 :(

kpturner avatar Aug 18 '19 21:08 kpturner

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

newtmex avatar Mar 21 '20 18:03 newtmex

I can confirm this, inheritance is broken, also for getters and attributes.

seflue avatar Aug 12 '20 00:08 seflue

@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.

Disorrder avatar Aug 12 '20 08:08 Disorrder

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/

ddannenb avatar Mar 08 '22 14:03 ddannenb