Delegate Middleware<TStoreState>
A Redux middleware is a higher-order function that composes a dispatch function to return a new dispatch function.
Namespace: Unity.AppUI.Redux
Assembly: Unity.AppUI.Redux.dll
Syntax
public delegate DispatcherComposer Middleware<TStoreState>(IStore<TStoreState> store)
Parameters
Type | Name | Description |
---|---|---|
IStore<TStoreState> | store | The store. |
Returns
Type | Description |
---|---|
DispatcherComposer | The dispatcher composer. |
Type Parameters
Name | Description |
---|---|
TStoreState | The type of the store state. |
Examples
The following example shows how to create a middleware that logs all actions.
// Middleware that logs all actions
var loggerMiddleware = (store) => next => action =>
{
Debug.Log($"Dispatching action: {action}");
// Call the next middleware in the chain
next(action);
};
// Apply the middleware to the store
var middlewares = Store.ApplyMiddlewares(loggerMiddleware);
var enhancer = Store.ComposeEnhancers(middlewares, DefaultEnhancer.GetDefaultEnhancer());
var store = Store.CreateStore(reducer, initialState, enhancer);
See Also
ApplyMiddleware<TState>(params Middleware<TState>[])