Last active
January 19, 2017 08:13
-
-
Save andycarrell/b0f4863d2a83503d94a3fe3bab079d62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Returns 'a' middleware | |
const combineMiddlewares = (...middlewares) => store => { | |
// Map over applying store | |
const stored = middlewares.map(mw => mw(store)) | |
return next => { | |
// Map over applying the next as 'next' | |
const [first, ...rest] = stored | |
const nextMiddlewares = [...rest, next] | |
// Should this be done in reverse? | |
// (apply 'next', then through the chain & mutate locally?) | |
const nexted = stored | |
.map((mw, i) => mw(nextMiddlewares[i])) | |
.reverse() | |
return action => compose(...nexted)(action) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment