Reputation: 1457
In the Mutations chapter, you can see an example that uses mapMutations to map mutations to component methods.
It also says that
You can commit mutations in components with this.$store.commit('xxx')
So the question comes, is committing a mutation directly from a component (not through an action) fine in vuex?
If it is, then this diagram may need to update:
Should I keep using the mapMutations method?
Upvotes: 3
Views: 830
Reputation: 6075
As far as I understood, actions are mainly used for asynchronous operations which might comprise multiple mutations. So yes, it's ok to directly use mutations, that's what they are made for. Only when you have more complex workflows involving multiple mutations you should wrap them in an action.
Upvotes: 4
Reputation: 4479
MapMuation
is just a helper that lets you use your defined mutations (in mutation-types) as methods of your component. It is exactly the same with $store.commit
but with an easier notation.
I don't know in which context your diagram is but mutations can be called from everywhere (components, services, actions, getters etc...) en will do its work finely by synchronously updating the store.
Upvotes: 0