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

Why use a "action" to commit a "mutation" ? #87

Closed
zhangqiangoffice opened this issue Aug 3, 2018 · 3 comments
Closed

Why use a "action" to commit a "mutation" ? #87

zhangqiangoffice opened this issue Aug 3, 2018 · 3 comments
Labels

Comments

@zhangqiangoffice
Copy link
Contributor

I don't know why you use a "action" to commit a "mutation" in the "src/vuex-i18n-store.js". I'm not very familiar with Vuex. Are there any benefits of such a design?

@tikiatua
Copy link
Member

tikiatua commented Aug 3, 2018

Hi @zhangqiangoffice

This is the recommended vuex flow. Components should only ever trigger actions, which in turn commit mutations to change the state. A component should not directly call a mutation and an action should not directly modify state. This helps to keep the flow of the application organized once it gets larger. Also all mutations can be inspected in the vue devtools in chrome.

@zhangqiangoffice
Copy link
Contributor Author

Where is the recommended vuex flow? I can't find it on the website "https://vuex.vuejs.org"

@tikiatua
Copy link
Member

tikiatua commented Aug 3, 2018

You can find a good illustration directly on the start page of the vuex documentation.

However, the documentation is somewhat hard to grasp, when starting out with vuex. There should be some talks in youtube that explain it quite well.

It basically boils down to components dispatch (async) actions, actions commit synchronous mutations, mutations change state in the store.

Then there are some helper functions to make common things a little easier to write.

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

No branches or pull requests

2 participants