championswimmer / vuex-module-decorators

TypeScript/ES7 Decorators to create Vuex modules declaratively
https://championswimmer.in/vuex-module-decorators/
MIT License
1.8k stars 170 forks source link

Modules inheritance #125

Open Disorrder opened 5 years ago

Disorrder commented 5 years ago

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?

kpturner commented 5 years ago

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

newtmex commented 4 years ago

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

seflue commented 4 years ago

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

Disorrder commented 4 years ago

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

ddannenb commented 2 years ago

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/