React redux-thunk redux-logger
import {applyMiddleware, createStore, compose, combineReducers} from 'redux'; //compose 组成 combine 联合 // import {combineReducers} from "redux-immutable"; import createLogger from 'redux-logger'; //applyMiddleware 应用中间件 createStore 创建存储 import thunk from "redux-thunk"; // 设置各种中间件 const logger = createLogger(); let middleware; if (globalConfig.debug) { //config.js 是否开启debug模式, 不会请求后端接口, 使用mock的数据 middleware = applyMiddleware(logger); //应用日志中间件 } else { middleware = applyMiddleware(); //应用中间件 } // 设置redux开发工具 const composeEnhancers = process.env.NODE_ENV !== 'production' && typeof window === 'object' && //webpack window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({}) : compose; //compose 组成 const enhancer = composeEnhancers( //设置redux开发工具 middleware, //applyMiddleware ); // 组合最终的store 3个参数 //initState 定义初始状态, 每个组件只需要关心自己的状态 默认 const store = createStore(combineReducers(reducers), initState, enhancer); //combine 联合 //enhancer 上面设置的 redux dev tools //const store = createStore(reducer,applyMiddleware(thunk));