-
Notifications
You must be signed in to change notification settings - Fork 20
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
Have options independent of module #5
Comments
The simplest implementation would be having 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 |
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' As you mention, using 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" })
}
} ? |
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. Anyway, I can of course define my own constructor, which allows the options factory and calls it before invoking |
Currently the
options: RegisterOptions
need to contain aname
. So if I want to use dependency injection, I will have to inject a different value into each module class.For my usage of vuex-class-modules, where I only use the proxy objects directly, the name parameter is not important, apart from having to generate a unique vuex module. The best solution would of course be to just have
Symbol()
as the module namespace, but that is completely incompatible with vuex I think.So my suggestion would be to either
name
option to be left out. Then, if it is not provided, generate a unique random name.name
to be a function, which is called to generate the name. Then the user can decide for themself whether to use a random or deterministic name.Another thought is to somehow use the class name when generating the vuex module name.
The text was updated successfully, but these errors were encountered: