Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

417
Views
VueJS/Vuex : how to handle two commits happening at the same time?

I'm learning VueJS and Vuex and I try to make a little management game with a Vuex store.

I have 100 food in the store and every day, my four Peons need to eat 1 unit of food.

So I watch the store for the mealtime in my component Peon.vue, of which four instances exist :

store.watch((state) => {
    if (state.time.hours === this.mealTime) {
      store.commit("mealTime");
    }
  });

And in my store index.js, the commit do this :

mealTime(state) {
  state.ressources.food = {
    ...state.ressources.food,
    quantity: state.ressources.food.quantity - 1,
  }
}

I have noticed that it doesn't work when I have more than 1 commit at the same time (imagine that 2 peons both eat at 7 am ?!). It goes in an infinite loop and the message :

Maximum recursive updates exceeded. This means you have a reactive effect that is mutating its own dependencies and thus recursively triggering itself. Possible sources include component template, render function, updated hook or watcher source function.

I could forget this issue and make them eat at different moment, but I guess I'll have this problem in other situations.

How can I handle multiple commits at the same moment ? Should I use Actions ? If I should use actions, is it possible to "chain" commit one after the other ?

Thanks for your help

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!