applyMiddleware<State> function
Connects the middleware
to the Redux Store
Applying middleware and passing it to Redux Store enables dispatched store actions to flow through to middlewares channel.
Check the example at createSagaMiddleware.
Note that, actions are first processed by the Store reducer and then sent to the middlewares channel.
Implementation
Middleware<State> applyMiddleware<State>(SagaMiddleware middleware) {
if (middleware is _SagaMiddleware) {
middleware.connectedToStore = true;
return (Store store, dynamic action, NextDispatcher next) {
next(action);
if (action != null) {
middleware.put(action);
}
return action;
};
} else {
throw InvalidOperation();
}
}