effects.defer
call, and an alternative effect should be returned. Here is an example of a bad deferred effect:defer
effect can also be used to wait a single tick, so something like defer(act(YourAction))
will allow the application to finish it's current tick and other queued work.defer((resolve, reject) => {})
to avoid the overly verbose defer(new Promise((resolve, reject) => {}))
version, but both are valid.console.log
, but can also be used to defer a promise or a desired synchronous batch behavior. A great example use case for a thunk is chaining a series of timeouts. Consider the following example:/* wait 1 second */, 'first timer done', /* wait 1 second */, 'second timer done'
, but in reality, it will be /* wait 1 second */, 'first timer done', 'second timer done'
. This is because the promises are kicked off immediately, before the effect manager handles them. In some cases, like non-dependent http requests, this is great, but for chaining timers, it is not. The solution, as you might have guessed, is wrapping our delay effect in a thunk, just like this:effects.act
has two ways of being called.+ 1
implementation seen above.