You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ReduxAsyncQueue middleware makes queueing redux actions painless. This allows you to fire multiple actions simultaneously and have them execute asynchronously in order.
The middleware will search for any action that has the queue property. It will then add the callback function to the corresponding queue. The queue key specifies to which queue this callback belongs. You may have several different queues for any given application.
For example, let's say we are making burgers (because they're delicious!). We can only make one burger at a time, but our friends keep coming up and saying they want one. You have 10 requests, but can only make one at a time. Here is how we'd write that delicious example out with the ReduxAsyncQueue middleware.
// This is the name of the queue. This does not need to match the action 'type' in 'makeBurger()'// You could for example call this `MAKE_FOOD` if you were also going to be cooking up some// sweet potato fries and wanted them in the same queue even though they are different actions.constMAKE_BURGER='MAKE_BURGER';functionmakeBurger(ingredients){return{type: MAKE_BURGER,payload: ingredients,};}functionqueueMakeBurger(burgerStyle){return{queue: MAKE_BURGER,callback: (next,dispatch,getState)=>{getIngredients(burgerStyle).then(ingredients=>{dispatch(makeBurger(ingredients));next();});}}}// Call the queue from your container / smart componentdispatch(queueMakeBurger(burgerStyle));
You'll notice the next() call within callback. That is the key to letting ReduxAsyncQueue know that you are ready to start making the next burger. If you do not call next() then the queue will not work.