* `takeEvery` allows concurrent actions to be handled. In the example above, * when a `USER_REQUESTED` action is dispatched, a new `fetchUser` task is * started even if a previous `fetchUser` is still pending (for example, the * user clicks on a `Load User` button 2 consecutive times at a rapid rate, the * 2nd click will dispatch a `USER_REQUESTED` action while the `fetchUser` fired * on the first one hasn't yet terminated) * * `takeEvery` doesn't handle out of order responses from tasks. There is no * guarantee that the tasks will terminate in the same order they were started. * To handle out of order responses, you may consider `takeLatest` below.
注意
takeEvery不可以保证effects结束顺序与发起顺序相同。
每发起一个action,即会执行一个effects
takeLeading
1 2 3 4 5 6
* Spawns a `saga` on each action dispatched to the Store that matches * `pattern`. After spawning a task once, it blocks until spawned saga completes * and then starts to listen for a `pattern` again. * * In short, `takeLeading` is listening for the actions when it doesn't run a * saga.
* Spawns a `saga` on each action dispatched to the Store that matches * `pattern`. And automatically cancels any previous `saga` task started * previously if it's still running. * * Each time an action is dispatched to the store. And if this action matches * `pattern`, `takeLatest` starts a new `saga` task in the background. If a * `saga` task was started previously (on the last action dispatched before the * actual action), and if this task is still running, the task will be * cancelled.