为什么选择 Curry Redux 中间件:state => next => action {} vs. (state, next) => action {}

Why Curry Redux Middleware: state => next => action {} vs. (state, next) => action {}

在阅读了关于 applyMiddleware 的 Redux's documentation on middleware and source code 之后,我不明白为什么中间件需要 curry 语法:

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

做不到同样的事情

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

applyMiddleware 中进行撰写调用:

dispatch = compose(...middleware)(middlewareAPI , store.dispatch)

不,因为它是一种将函数推迟到以后执行的方法。 ()=>() returns 一个函数对象,只有在调用 func obj 时才会执行。

关于此,可以找到与 Dan Abramov 的讨论 here。他说,

We could have made it (store, next) => action => () but I don't see a problem with just going all the way. You might want some configuration later, at which point options => (store, next) => action => () looks kinda arbitrary.

所以不,没有必要柯里化参数。