Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

423
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda