Fork me on GitHub
#re-frame
<
2019-06-26
>
kaneko12:06:34

I have a sequence of API calls to make, the order matters and I want to dispatch the next api call only if the current call succeeds. Is there a straight forward way of doing this? Currently I have an event handler for each of the api calls that I would like to make (uses :http-xhrio) and the on-success dispatches the next api call. But I find this hard to work with, maybe I should just have one event that runs all the api calls using cljs-http or something?

victorb20:07:11

take a look at https://github.com/Day8/re-frame-async-flow-fx for managing a flow of async events

manutter5113:06:46

Personally I think the setup you have right now is the most straight-forward--all your steps are laid out explicitly, and it’s easy to see what order they’re happening in, plus if an error occurs you can tell exactly at what step it happened, and can have custom error handling (if needed) for each step.

manutter5113:06:53

What are you finding hard about working with that setup?

kaneko13:06:01

What you are saying does make sense. I think the problem is that the sequence of these api calls depends on user input. So each of my api-call-handler's on-success dispatches to a common event-handler that dispatches the next api-call. I also have to build some state from the response and pass it along. I'm also quite new to clojure so that makes it a little harder too!

manutter5113:06:42

Yeah, if the sequence of calls depends on user input, I think it’s definitely better to keep each step in a separate handler. But it also sounds like you’re starting to get into a level of complexity that might benefit from a state machine of some kind.

kaneko13:06:31

I'll read up on state machines and have a play around, thank you so much 🙂

Jag Gunawardana16:06:30

The kee-frame project has a nice way of chaining events e.g. your sequence of http-xhrio above. I found that it was useful to use this and it was easy to snap into an existing re-frame project.