1

What is the proper and best way to queue events on Javascript and then fire them one after another in right order (FIFO).

I've made something like that:

https://jsfiddle.net/zjsh0xq3/

My component is getting state from Vuex / Vue instance and it is synchronized according to DOM position (if those components will be resized from outside). For this example I made List component with position of items but the idea is the same.

So after I fired method on ListItem the parent component List is storing those events (data for operation) in array. And after that events are fired in right order one after another, but only if there is callback from $emit fired to say to List that this state of List has been changed in Vuex / Vue instance.

Does anyone have any better idea to solve this case or somewhere ready tool for queuing events?

I thought about promises like in this article: https://gist.github.com/anvk/5602ec398e4fdc521e2bf9940fd90f84

But I don't know how to prevent promises from being resolved until callback is called.

Thanks for advices!

Canor
  • 909
  • 1
  • 8
  • 25
  • duplicate [here](https://stackoverflow.com/questions/24586110) i believe – Paul Rdt Jun 14 '18 at 12:14
  • There is no callback function inside those Promises and Promises are resolved one after another automatically. I need to have ability to prevent it from being called until I say so. – Canor Jun 14 '18 at 12:44

0 Answers0