一、类似于redux-logger的打印效果
const logger = store => next => action => {
console.group(action.type)
console.log(colors.yellow('pre state'), store.getState())
console.log(colors.blue('action'), action)
let result = next(action)
console.log(colors.green('next state'), store.getState())
console.groupEnd(action.type)
return result
}
store = createStore(
rootReducer ,
applyMiddleware(logger)
)
实现的效果是这样的
二、'redux-thunk’类似,可以在action 里传入 dispatch getState
const thunk = store => next => action =>{
typeof action === 'function' ?
action(store.dispatch, store.getState) :
next(action)
}
三、