Code Monkey home page Code Monkey logo

Comments (3)

bodograumann avatar bodograumann commented on August 23, 2024

The simplest implementation would be having VuexModule as:

export class VuexModule {
  private __options: RegisterOptions;
  constructor(options: RegisterOptions | ((className: string) => RegisterOptions)) {
    if (typeof options === "function") {
      options = options(this.constructor.name);
    }
    this.__options = options;
  }
}

The problem with using this.constructor.name is that in the minified version it will be mangled. Maybe multiple different classes might even get the same name then

from vuex-class-modules.

gertqin avatar gertqin commented on August 23, 2024

I don't see any use cases other than DI where you wouldn't want to add a name when registering the modules (for instance in Vue Devtools you would like to be able to identify the modules). Vuex' store.registerModule also requires a name (path).

As you mention, using constructor.name has the problem that it will be mangled when minified, and I'm not sure the names will be unique, so I don't like this solution.

For your need, can't you just change the constructor of your modules to something like:

@Module
class MyModule extends VuexModule {
  constructor(store: Store) {
    super({ store, name: "myModule" })
  }
}

?

from vuex-class-modules.

bodograumann avatar bodograumann commented on August 23, 2024

This might not pose an immediate problem, but it goes against the principles of dependency injection, because then every module must make sure not to collide with any other.
When I said, using the module class, I meant “based on the module class”. So some uid could be added.

Anyway, I can of course define my own constructor, which allows the options factory and calls it before invoking super. So it’s ok that this is not changed here.

from vuex-class-modules.

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.