August 2017
Beginner
374 pages
10h 41m
English
The problem in our previous attempts of implementing middleware was the chaining--we keep replacing the (enhanced) dispatch function with a new one that calls the preceding one.
There is a different way to implement chaining--the middleware could get the next() function as a parameter instead of directly accessing store.dispatch:
function logger (store) { return function wrapDispatchWithLogger (next) { return function dispatchAndLog (action) { if (console.group) console.group(action.type) console.info('dispatching', action) const result = next(action) console.log('new state', store.getState()) if (console.groupEnd) console.groupEnd(action.type) return result } }}
Since we are nesting a lot of higher-order functions ...
Read now
Unlock full access