2021-09-30
2512
#vue
Michael Gallagher
1742
Sep 30, 2021 ⋅ 8 min read

Vuex showdown: Mutations vs. actions

Michael Gallagher Living in the vibrant city of Buenos Aires, developing project management software with Teamwork. Modern JS is my passion; Vue, my tool of choice.

Recent posts:

Justin Kitagawa Leader Spotlight

Leader Spotlight: Riding the rocket ship of scale, with Justin Kitagawa

We sit down with Justin Kitagawa to learn more about his leadership style and approach for handling the complexities that come with scaling fast.

Jessica Srinivas
Mar 29, 2024 ⋅ 8 min read
Nx Adoption Guide: Overview, Examples, And Alternatives

Nx adoption guide: Overview, examples, and alternatives

Let’s explore Nx features, use cases, alternatives, and more to help you assess whether it’s the right tool for your needs.

Andrew Evans
Mar 28, 2024 ⋅ 9 min read
Understanding Security In React Native Applications

Understanding security in React Native applications

Explore the various security threats facing React Native mobile applications and how to mitigate them.

Wisdom Ekpotu
Mar 27, 2024 ⋅ 10 min read
Warp Adoption Guide: Overview, Examples, And Alternatives

warp adoption guide: Overview, examples, and alternatives

The warp web framework for Rust offers many enticing features. Let’s see when and why you should consider using warp in your projects.

Ukeje Goodness
Mar 26, 2024 ⋅ 8 min read
View all posts

2 Replies to "Vuex showdown: Mutations vs. actions"

  1. Hi Michael, thanks for this nice article! Vuex is a great tool but I think we are lacking some guidelines to follow to get it right.

    I often read that mutations should be one-liners , or at least remain really simple… Why? The doc describes a mutation as a transaction, this term makes me think that we could write as much code as needed in a single mutation to enforce state coherency.

    Let’s take a simple example: an image with its width and height stored in the state, and a boolean to keep aspect ratio when changing the width or height. Would you advise to write the keep aspect ratio logic in the ´setWidth’ and ´setHeight’ mutations, or move it into the actions?

    Thanks!

  2. Hey Jonathan,

    Glad you like the article, I’ve tried my best not to be overly opinionated about it. I normally use actions, even if it is just wrapping a mutation. The question for me in your example is whether there are 1 or 2 actions/mutations. You could have the 2 you mention, or maybe `setDimensions` which would set both? The reason I say it is that, to me, the width and height will probably always be set together, considering them as separate transactions for either mutations or actions, doesn’t give any additional benefit to traceability, readability or reusability. And this would cover your aspect ratio point also.

    Cheers
    Mike

Leave a Reply