Questions on the proper use and handling of `done` callbacks
See original GitHub issuePreface: trying to use choo on a project, and I’m somewhat confused, on several levels, about the proper usage of the done
callback in effects and how it relates to the callback provided in the send
method.
Here are my particular questions and areas where I’d appreciate some clarifications:
- In an effect handler, I understand the need to pass the
done
cb to subsequentsend
calls, to maintain the chain and allow errors to propagate upwards. But how should I handle the cb if I want to send 2+ actions from a single effect (e.g. I make an API call which returns data applicable to two separate models)? The following seems incorrect, but I’m not sure what the correct behavior should be:
myeffect: (state, data, send, done) => {
... make call to server ...
send('foo:update', newFoo, done);
send('bar:update', newBar, done);
}
-
Aside from effects sending actions to reducers, we often send actions from views. Presumably the
send
provided to views is the samesend
provided to effects. So that implies that one could provide their own callback to be called once the sent action has completed. My question is if there’s is any common/encouraged use for this? I could imagine using it to update the html/UI if an error was encountered (which seems generally useful). But I could also imagine that such usage could present a race with the view being retriggered (because the state changed) and all sorts of unpredictable/undesired behavior occurring… -
Are there any examples of applications making use of the done callback in a non-trivial manner? It would be great to have something to reference to, and none of the examples in this repository seem to make use of it (there are cases of passing it an error, but as far as I can tell nothing acts on that error).
Thanks!
Issue Analytics
- State:
- Created 7 years ago
- Comments:22 (11 by maintainers)
Top GitHub Comments
Well, classical Node style then.
@jbucaran Your effect shouldn’t know if it’s being called by another asynchronous function though, should it? The caller would depend on knowing when the effect finishes.