Delegate StoreEnhancer<TState>
A function to enhance the store creation.
Namespace: Unity.AppUI.Redux
Assembly: Unity.AppUI.Redux.dll
Syntax
public delegate StoreEnhancerStoreCreator<TState> StoreEnhancer<TState>(StoreEnhancerStoreCreator<TState> createStore)
Parameters
Type | Name | Description |
---|---|---|
Store |
createStore | The store creation function. |
Returns
Type | Description |
---|---|
Store |
The enhanced store creation function. |
Type Parameters
Name | Description |
---|---|
TState | The type of the store state. |
Examples
The following example shows how to enhance the store creation to replace the dispatcher with a custom dispatcher.
// Enhancer that logs the action and the state before and after the action.
var enhancer = (createStore) => (reducer, initialState) =>
{
var store = createStore(reducer, initialState);
var originalDispatcher = store.dispatcher;
store.dispatcher = new Dispatcher(action =>
{
Debug.Log($"Dispatching action: {action}");
originalDispatcher(action);
Debug.Log($"State after action: {store.GetState()}");
});
return store;
};
// You can compose enhancers using Store.ComposeEnhancers
var composedEnhancer = Store.ComposeEnhancers(enhancer, DefaultEnhancer.GetDefaultEnhancer());
// Create the store with one enhancer or a composed enhancer
var store = Store.CreateStore(reducer, initialState, composedEnhancer);