azizj
azizj

Reputation: 3787

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)

Upvotes: 1

Views: 1406

Answers (2)

azizj
azizj

Reputation: 3787

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.

Upvotes: 1

Karan Jariwala
Karan Jariwala

Reputation: 727

No, because it a way to defer an function to be executed later. ()=>() returns a function object which only get executed later when the func obj is called.

Upvotes: 0

Related Questions