Search code examples
javascriptreduxmiddleware

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


After reading both Redux's documentation on middleware and source code on applyMiddleware, I don't understand why middleware need the curry syntax:

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

Couldn't the same thing be achieved by doing

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

Making the compose call in applyMiddleware:

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

Solution

  • A discussion with Dan Abramov can be found here regarding this. He said,

    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.

    So no, it is not necessary to curry the parameters.