From af474ba34cb3aae31c418228561f6e23a4b66bb2 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Wed, 22 Jul 2015 19:53:40 +0300 Subject: [PATCH] Inline composeMiddleware because it is not used outside applyMiddleware --- src/utils/applyMiddleware.js | 18 +++++------------- src/utils/composeMiddleware.js | 13 ------------- 2 files changed, 5 insertions(+), 26 deletions(-) delete mode 100644 src/utils/composeMiddleware.js diff --git a/src/utils/applyMiddleware.js b/src/utils/applyMiddleware.js index 2cb09f9b47..0f320f293e 100644 --- a/src/utils/applyMiddleware.js +++ b/src/utils/applyMiddleware.js @@ -1,5 +1,4 @@ import compose from './compose'; -import composeMiddleware from './composeMiddleware'; /** * Creates a higher-order store that applies middleware to a store's dispatch. @@ -11,22 +10,15 @@ import composeMiddleware from './composeMiddleware'; export default function applyMiddleware(...middlewares) { return (next) => (reducer, initialState) => { var store = next(reducer, initialState); - var middleware = composeMiddleware(...middlewares); - var composedDispatch = () => {}; - - function dispatch(action) { - return composedDispatch(action); - } + var dispatch = store.dispatch; + var chain = []; var middlewareAPI = { getState: store.getState, - dispatch + dispatch: (action) => dispatch(action) }; - - composedDispatch = compose( - middleware(middlewareAPI), - store.dispatch - ); + chain = middlewares.map(middleware => middleware(middlewareAPI)); + dispatch = compose(...chain, store.dispatch); return { ...store, diff --git a/src/utils/composeMiddleware.js b/src/utils/composeMiddleware.js deleted file mode 100644 index 98927a21b5..0000000000 --- a/src/utils/composeMiddleware.js +++ /dev/null @@ -1,13 +0,0 @@ -import compose from './compose'; - -/** - * Compose middleware from left to right - * @param {...Function} middlewares - * @return {Function} - */ -export default function composeMiddleware(...middlewares) { - return args => rawDispatch => { - var dispatchChain = middlewares.map(middleware => middleware(args)); - return compose(...dispatchChain, rawDispatch); - }; -}