Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modules inheritance #125

Open
Disorrder opened this issue May 20, 2019 · 5 comments · May be fixed by #313
Open

Modules inheritance #125

Disorrder opened this issue May 20, 2019 · 5 comments · May be fixed by #313

Comments

@Disorrder
Copy link

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:

module.state = moduleOptions && moduleOptions.stateFactory ? stateFactory : stateFactory()

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
Copy link

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
Copy link

newtmex commented Mar 21, 2020

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
Copy link

seflue commented Aug 12, 2020

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

@Disorrder
Copy link
Author

@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
Copy link

ddannenb commented Mar 8, 2022

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants