redux middleware 解读

middleware

什么是middleware,个人理解就是一个可以让你在dispatch action的时候,可以同时做几个动作,比如想打印日志,异步请求

middleware运行

middleware logger

export const logger = store => next => action = {
  console.log(1111)
  next(action)
  console.log(2222)
}

export const logger1 = store => next => action = {
  console.log(333333)
  next(action)
  console.log(44444)
}

运行

const dispatch_1 = applyMiddleware([logger, logger1])

dispatch_1 = logger(logger1(store.dispatch))

这是执行dispatch(action)的时候
第一步就是执行logger函数
1,打印出1111
2,执行logger1(store.dispatch)(action)
3, 打印出333
4,执行store.dispatch(action)
4,打印出222
5,打印出 4444

你可能感兴趣的:(redux middleware 解读)