Comments (5)
There you go
https://github.com/championswimmer/vuex-module-decorators/blob/master/test/vuexmodule_constructor.ts
from vuex-module-decorators.
@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.
from vuex-module-decorators.
sure will add an example for this
from vuex-module-decorators.
Hi , I made another attempt.
heres my store code...
export const mod = <ModuleOptions>{name:"su-data",namespaced:true,stateFactory:false};
const _service = DIContainer.get<SvcServiceUser>(IOC_TYPES.SU_SERVICE);
const suData = new ServiceUserData(_service,mod)
Vue.use(Vuex)
export default new Vuex.Store({
state: {},
modules: {
suData
},
})
heres my code for my VuexModule constructor
@Module
export class ServiceUserData extends VuexModule {
private _service : SvcServiceUser;
constructor(
service: SvcServiceUser,
module: Mod<ThisType<{}>,any>
)
{
super(module)
and finally this is the error
Uncaught TypeError: Cannot read property 'actions' of undefined
at new VuexModule (vuexmodule.js?84ac:5)
at new ServiceUserData (data-service-user.ts?18e2:43)
at stateFactory (module.js?f71e:7)
at eval (module.js?f71e:19)
at Module (module.js?f71e:43)
at DecorateConstructor (Reflect.js?8e39:541)
at Object.decorate (Reflect.js?8e39:130)
at Module.__decorate (tslib.es6.js?d2cb:53)
at eval (data-service-user.ts?18e2:26)
highlighting module.actions
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var VuexModule = /** @class */ (function () {
function VuexModule(module) {
this.actions = module.actions;
this.mutations = module.mutations;
this.state = module.state;
this.getters = module.getters;
this.namespaced = module.namespaced;
this.modules = module.modules;
}
return VuexModule;
}());
exports.VuexModule = VuexModule;
//# sourceMappingURL=vuexmodule.js.map
Obviously there problem in the constructor and the manner in which (module) is constructed. Any suggestions will be helpful, I think what you done here is great
thanks..
from vuex-module-decorators.
you can do it like:
constructor(proxy: BaseProxy, module: Mod<ThisType<{}>, any> = {}) {
super(module)
this.proxy = proxy
}
But NuxtJS store will raise this:
Cannot stringify arbitrary non-POJOs ........
from vuex-module-decorators.
Related Issues (20)
- MutationAction not working with RemoteData union type
- got error when use @Mutation in app.config.errorHandler HOT 2
- MutationAction not having access to module state? HOT 5
- How can I split up an module-class HOT 1
- Conflict with NuxtJS third-party modules HOT 2
- When will you release the new version ?
- MutationAction still not works HOT 2
- peer vuex@"3" from [email protected] HOT 3
- Setting an object through MutateAction throws an exception HOT 3
- Action method question HOT 1
- Missing github release and changelog for v2 HOT 2
- v2.0.0 there are any breaking changes ? HOT 2
- Can vite hot update be supported?
- How can I use Try catch inside @MutationAction?
- in @Mutation,this is undefined HOT 1
- In @Mutation, how to call another Mutation, this.xxx is undefined HOT 1
- vue.reactive is not a function (Nuxtjs, Typescript)
- MutationAction never commits changes, if component switched
- Using vuex-module-decorators with vue2 HOT 1
- fix: support typescript 4.8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vuex-module-decorators.