Fork me on GitHub

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?


take a look at for managing a flow of async events


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.


What are you finding hard about working with that setup?


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!


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.


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.