Migrating dispatch actions to effects
In our to-do app, we had four actions:
- Adding a task
- Removing a task
- Toggle completed
- Clear completed
Let's look at each one in more detail.
Adding a task
The following code snippet shows how to add a task to our store:
store.dispatch({ Â Â Â type: "ADD_TODO", Â Â Â title: inputValue });
With Rematch, this type of dispatch works out of the box, but it isn't recommended to use because it isn't type-safe and isn't very readable.
In Rematch, we adopt an alternative strategy of what Redux offers initially with the dispatch
method. When Rematch initialises the store through the init()
function or we add a new model using the store.addModel()
function, we iterate over all the models and we create shortcuts for each reducer and effect for each model of our store. This means that we can access any reducer or effect of our store using direct access, such as...