DEV Community

Discussion on: Mapping for a Vuex beginner

 
mattarc profile image
mattarc

Thanks for the response, Nihar. I understand the need for mutations in the way that as you say we have asynchronous actions for synchronous mutations. But essentially, yes you have hit the nail on the head in your first reply to my comment,
"why is there a need to map mutations in a Vue component since we can just map actions because mutations are, in the end, committed by actions?"
This I still don't understand. It seems to me that a mapped action would commit the mutation in the store; there would never be a need to call a mutation from a mapping?

Thread Thread
 
napoleon039 profile image
Nihar Raote

I honestly haven't found an answer to it as well. It's like no one else wonders why we need to commit mutations in the store when we can dispatch an action for it. But since there's an example for mapping mutations in the component in the Vue documentation, there should be a reason.

Though I haven't seen this reasoning anywhere I think it's because an action is expected to do some asynchronous stuff along with committing mutations. So maybe a use case for committing mutations in the component is when actions do more than just commit mutations and we only need to commit a mutation and not the other stuff?

I'll try to see if there is an answer anywhere like Stackoverflow or ask on Twitter if I still can't find one.