如何定制自定义反应redux中间件?

时间:2022-04-27 19:42:20

Going through the process of middleware, Dan defines next to the the original dispatch, but in creating the middleware, he doesn't. Where and how is next defined here:

通过中间件的过程,Dan定义了原始调度的旁边,但是在创建中间件时,他没有。这里定义的位置和方式如下:

const logger = store => next => action => {
  console.group(action.type)
  console.info('dispatching', action)
  let result = next(action)
  console.log('next state', store.getState())
  console.groupEnd(action.type)
  return result
}

1 个解决方案

#1


0  

Where

next is supplied by applyMiddleware.

next由applyMiddleware提供。

How

From the referenced source,

从引用的来源,

var middlewareAPI = {
  getState: store.getState,
  dispatch: (action) => dispatch(action)
}
chain = middlewares.map(middleware => middleware(middlewareAPI))
dispatch = compose(...chain)(store.dispatch)

middlewareAPI is the first level argument passed to a middleware. It is named store conventionally.

middlewareAPI是传递给中间件的第一级参数。它通常被命名为商店。

store.dispatch is the supplied next, which is the second level argument.

store.dispatch是提供的next,这是第二级参数。

#1


0  

Where

next is supplied by applyMiddleware.

next由applyMiddleware提供。

How

From the referenced source,

从引用的来源,

var middlewareAPI = {
  getState: store.getState,
  dispatch: (action) => dispatch(action)
}
chain = middlewares.map(middleware => middleware(middlewareAPI))
dispatch = compose(...chain)(store.dispatch)

middlewareAPI is the first level argument passed to a middleware. It is named store conventionally.

middlewareAPI是传递给中间件的第一级参数。它通常被命名为商店。

store.dispatch is the supplied next, which is the second level argument.

store.dispatch是提供的next,这是第二级参数。