Fork me on GitHub
#re-frame
<
2019-08-15
>
stefan19:08:49

👋… Does dispatch-n dispatch events synchronously? I see in the docs that they are dispatched in the order provided, and I’m assuming that means they are also synchronous?

stefan19:08:37

If not, what is the recommended way of dispatching an event only after another event has completed?

Lu19:08:40

There was a discussion about this some time ago.. the order simply dictates when the events are dispatched.. but if one takes longer (say an http request) the following event in your dispatch-n vector will not wait for the callback to be executed

Lu20:08:52

To cope with this you might want to call your second or so event from the callback of your http request event... If you are chaining say three events that only manipulate the state I reckon those calls happen synchronously .. can anybody confirm?

Lu20:08:26

Yes indeed.. if there’s no “waiting” you can rely on the order: https://github.com/Day8/re-frame/blob/master/docs/API.md

stefan20:08:40

In my case the first event only manipulates state (sets some ids that I want to use for a graphql query), and the 2nd event makes the query using re-graph.

stefan20:08:41

I see that they are dispatched in order, I just wonder if event 2 would wait for event 1 to “resolve”, or if I added a 3rd event could I rely on the fact that the re-graph query would resolve before dispatching the 3rd event.

Lu20:08:57

From the re-graph docs it looks like there is a callback involved .. so I think it’s best to dispatch the event from there ..

stefan20:08:32

That makes sense

stefan20:08:46

thanks

🙏 4