Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

416
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda