Effects trigger side effects like API calls and handle the result:
- An Effect listens for a specific action
- That action triggers the actual side effect
- The Effect needs to return a new action as soon as the side effect completed
The code above creates an effect. As soon as the
LoadTodos action has been dispatched the API call will be executed.
Depending on the result of the API call a new action will be dispatched:
The effect needs to be registered using
It is important to handle possible API errors with
catchError to make sure that the effect source does not complete.
A completed effect source will stop listening to actions, and the effect does not work anymore.