2
我正在閱讀applyMiddleware
的源代碼,並在一些分頁中,他們稱這種方式爲applyMiddleware(...middleware)
。那麼next
參數何時通過?applyMiddleware()中的next是什麼?
export default function applyMiddleware(...middlewares) {
return (next) =>
(reducer, initialState) => {
var store = next(reducer, initialState);
var dispatch = store.dispatch;
var chain = [];
var middlewareAPI = {
getState: store.getState,
dispatch: (action) => dispatch(action)
};
chain = middlewares.map(middleware => middleware(middlewareAPI));
dispatch = compose(...chain, store.dispatch);
return {
...store,
dispatch
};
};
}
你有讀過[**'applyMiddleware' **](http://redux.js.org/docs/api/applyMiddleware.html)文檔嗎? –