configureStore we get hold of the global store object.
At the same time we can pass a configuration to initialize our feature reducers, meta reducers, initial state and extensions.
At first, we do not need any configuration to get started.
Let`s just get hold of the store instance:
store instance we can already add reducers (dynamically), select state, dispatch actions and create effects.
We can configure the feature reducers via the configuration object. The reducers will be ready at store initialization.
It is possible to add feature reducers dynamically later like this:
We can set the initial state of the store via the configuration object. The initial state keys must match the provided reducer keys:
See how the initial state is available in a feature reducer:
Meta reducers are executed before the "normal" feature reducers. With meta reducers we can pre-process actions and state.
Most MiniRx Extensions like the Undo Extension, Logger Extension or the Immutable Extension are implemented with a meta reducer.
A meta reducer is a function which takes a reducer and returns a new reducer.
Let's see how to implement a simple Debug meta reducer:
Now we can add the
debug meta reducer to the
metaReducers array of the configuration object:
You can add many meta reducers to the array. The meta reducers will be executed from "left to right".