Fork me on GitHub
#re-frame
<
2022-06-22
>
sun-one19:06:53

Is their an approach within an event for the equivalent of a dispatch-sync (which seems to be not allowed)? Currently I have an event handler that uses the dispatch fx. The issue is that the event that's getting called from the dispatch fx is getting pushed to the bottom of the queue and so events that have already been dispatched don't get that events modification (and so they have incorrect data in my case as event needs to be processed immediately). The work around I did here was just to refactor a function out of the event I'm trying to call into and use that function within the event. Is there a better way where I can instead use an fx that's equivalent to dispatch-sync? One approach I had considered was writing some fx that pushes the event at the top of the event queue?

p-himik19:06:39

> The work around I did here was just to refactor a function out of the event I'm trying to call into and use that function within the event. I'd say it's not a workaround but rather the right way to do it.

p-himik19:06:06

Otherwise, it becomes incredibly easy to mess things up. Imagine this effects map, for example:

{:fx [[:dispatch-sync [:a]]
      [:dispatch [:b]]
      [:dispatch-sync [:c]]]}
What should happen here? And yes, you might have an answer, but someone else reading that very code could easily have a completely different intuition.

sun-one20:06:09

Yea fair enough, I'm just wondering if this is the conventional way to handle it, which it sounds like it is.