Closed sebas5384 closed 7 years ago
Solution proposal:
export function handleMiddlewares(listeners) {
return store => {
const middlewares = Object.keys(listeners).map(type => {
return { type, middleware: listeners[type](store) }
})
return next => action => {
const matched = middlewares
.filter(({ type }) => type === action.type)
.shift()
if (!matched) {
return next(action)
}
return matched.middleware(next)(action)
}
}
}
Middlewares using handlers should had the possibility of declaring something before the dispatch cycle. For example:
https://github.com/choko-org/redux-boot/blob/master/src/processModules.js#L33-L42