applyMiddleware<T> function
Apply middleware to a reducer
Implementation
Reducer<T> applyMiddleware<T>(
Reducer<T> reducer,
List<ReduxMiddleware<T>> middlewares,
) {
return (T state, Action action) {
// Create a chain of middleware
void Function(Action) next = (Action action) {
reducer(state, action);
};
for (var i = middlewares.length - 1; i >= 0; i--) {
final middleware = middlewares[i];
final currentNext = next;
next = (Action action) {
middleware(
ReduxStore(state, reducer),
action,
currentNext,
);
};
}
next(action);
return state;
};
}