August 2017
Beginner
374 pages
10h 41m
English
Instead of applying middleware by monkeypatching, we can now take a store object, create the enhanced dispatch function by applying the middleware functions, and then return a new store object:
function applyMiddleware (store, middlewares) { const m = middlewares.slice() m.reverse() // reverse array, so that the first middleware in the array ends up being applied first const dispatch = store.dispatch m.forEach(middleware => dispatch = middleware(store)(dispatch) ) return Object.assign({}, store, { dispatch })}
This is not the official implementation of applyMiddleware() that ships with Redux. However, it is pretty similar, but different in three important aspects. The official implementation has the following features: ...
Read now
Unlock full access