GithubHelp home page GithubHelp logo

Comments (5)

championswimmer avatar championswimmer commented on May 22, 2024 8

There you go

https://github.com/championswimmer/vuex-module-decorators/blob/master/test/vuexmodule_constructor.ts

from vuex-module-decorators.

gregveres avatar gregveres commented on May 22, 2024 1

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

championswimmer avatar championswimmer commented on May 22, 2024

sure will add an example for this

from vuex-module-decorators.

kwekujoe avatar kwekujoe commented on May 22, 2024

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.

chantouchsek avatar chantouchsek commented on May 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.