Skip to content
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

Allow access to setter mutations #11

Closed
bodograumann opened this issue Feb 27, 2019 · 3 comments
Closed

Allow access to setter mutations #11

bodograumann opened this issue Feb 27, 2019 · 3 comments

Comments

@bodograumann
Copy link
Collaborator

When using the generateMutationSetters option, for each state property a mutation is generated, that sets the property.

Those setter mutations are only available inside of actions, not when using the module instance directly.

Do you think we should allow access from the outside? Or would you say that it is a much better practice to only do changes in the actions?

@gertqin
Copy link
Owner

gertqin commented Feb 28, 2019

So you want to do something like:

@Module({ generateMutationSetters: true })
class MyModule extends VuexModule {
  foo = "bar";
}
const myModule = new MyModule({ store, name: "myModule" });
myModule.foo = "baz";

?

It would not be hard to implement, but I'm not sure whether it is against the design principles of vuex (flux) or not. Do you think it would be beneficial to allow?

@bodograumann
Copy link
Collaborator Author

Yes this is what I mean.

I‘m not completely sure this follows the flux principles, but there are two reasons which let me lean towards yes:

  • It is not the default setting, you have to enable generateMutationSetters.
  • Even though the syntax is different, it simply commits a mutation, which is perfectly fine in flux as I understand it.

@gertqin
Copy link
Owner

gertqin commented Mar 9, 2019

Alright, I'll implement this. Although I think I'll keep it as an undocumented feature, as I'm still not sure whether this should be encouraged or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants