Model & Controllers
Cook and manage DApp's states by Redux Toolkit.
Single model - Multiple controllers
Model
Typically, the model always has a single file that is to merge all the controllers' states into the store.
Following the template, your DApp's state is isolated in a store named myapp
. If you installed Redux Devtool, you are able to inspect the myapp
states clearly.
Additionally, the model will merge all states in reducer
(i.e. main
is the current state declared in the reducer) which are exported from controllers. To import a new state, you merely need to add the state into the reducer.
Controllers
Controllers typically are to fetch raw data, process it to good forms, and export it to the model.
By the example, the name and struct of the state had been assigned at lines 15, 16. The function increaseCounter
is to compute and return the next state partially which will mutate the current state in slice (i.e. line 38 to build a state and line 44 to catch the next state from increaseCounter
).
Examine Best Practices for more examples.
Last updated