Open lewenweijia opened 5 years ago
// 中间件注入
const store = createStore(reducer, applyMiddleware(middlewares));
const middlewareAPI = {
getState: store.getState,
dispatch: (action ...args) => store.dispatch(action, ...args);
}
const chain = middlewares.map(m => m(middlewareAPI));
compose(...chain)(store.dispatch)
const compose = fns => fns.reduce((a, b) => (...args) => a(b(..args)))