constructor vuex - module
See original GitHub issueI am trying to inject my class which extends VuexModule using a DI container based on inversifyjs.
I Would have to pass the VuexModule constructor to the DI container then inject it when the class is instantiated to be passed to super().
It would be helpful if you could provide an example of :
/*
- To use with
new VuexModule(<ModuleOptions>{})
syntax
*/
cheers.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How can I use a constructor in a module? · Issue #105 - GitHub
I need to do some initialization work whenever the module is constructed. But when I add the super(); call, it expects a module...
Read more >API Reference | Vuex
Store Constructor Options #. state #. type: Object | Function. The root state object for the Vuex store.
Read more >Overview | vuex-module-decorators - championswimmer
Typescript/ES7 Decorators to make Vuex modules a breeze. ... /app/store/posts.ts import { VuexModule, Module, Mutation, Action } from ...
Read more >Way to make inheritance in Vuex modules - Stack Overflow
I put my reusable vuex code in small classes. E.g.. crud.js export default class { constructor ( endpoint ) { this.state = {...
Read more >vuex-class-modules - npm
Typescript class decorators for class-style vuex modules. ... The other module can be registered through the constructor (suitable if the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There you go
https://github.com/championswimmer/vuex-module-decorators/blob/master/test/vuexmodule_constructor.ts
@orgertot I believe the answer you were looking for was provided here on issue #105. The answer from @championswimmer was that you shouldn’t be using the constructor syntax of typescript for your Modules. I find that answer very unsatisfactory since that is our style guide - we do all of our initialization inside constructors and then we unit test the constructor setup the class properly.
I think that @championswimmer answered your question with his example of how he would do unit testing on a store module, by creating the store, then sending it messages. That’s not really how I would prefer to test my modules, but if you can’t instantiate them, then I guess that is the best we can do.
I know your original question was a long time ago and you have probably found another way around this. I am just migrating to vue from another framework where we have lots of existing typescript code that is all unit tested. I am just trying to figure out the best way to do the migration.