ES6 generators make asynchronous flows easy to read, write, and test. Create complex side effects without getting bogged down by the details.
Sagas enable numerous approaches to tackling parallel execution, task concurrency, task racing, task cancellation, and more. Keep total control over the flow of your code.
Assert results at each step of a generator or for a saga as a whole. Either way, side effect testing is quick, concise, and painless, as testing should be.
Suppose we have a UI to fetch some user data from a remote server when a button is clicked. (For brevity, we'll just show the action triggering code.)
The component dispatches a plain object action to the store. We'll create a Saga that watches for all USER_FETCH_REQUESTED actions and triggers an API call to fetch the user data.