Redux: Could the function applyMiddleware receives array as param?

Created on 30 Aug 2016  路  4Comments  路  Source: reduxjs/redux

Do you want to request a _feature_ or report a _bug_?
feature.

What is the current behavior?
@param {...Function} middlewares The middleware chain to be applied.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar.

no

What is the expected behavior?

receives array as param?

Which versions of Redux, and which browser and OS are affected by this issue? Did this work in previous versions of Redux?

all version

Because we can easily apply different middleware according to different environment, if applyMiddleware receives array as param.

Most helpful comment

Usually I do something like this when I want to deal with different environnements

const middlewares = [
  thunkMiddleware,
  reactRouterMiddleware,
  process.env.NODE_ENV !== 'production' && loggerMiddleware,
].filter(Boolean);

const enhancer = compose(applyMiddleware(...middlewares));

All 4 comments

If you want to send applyMiddlewares an array, why not just use something like ramda's apply? Or even the native js implementation on the Function prototype?

The variadic version is pretty widely used and accepted, its build into countless production apps, embedded in thousands of tutorials. The payoff for changing that api here seems small to me.

Usually I do something like this when I want to deal with different environnements

const middlewares = [
  thunkMiddleware,
  reactRouterMiddleware,
  process.env.NODE_ENV !== 'production' && loggerMiddleware,
].filter(Boolean);

const enhancer = compose(applyMiddleware(...middlewares));

Oh i forgot that you can spread args like that, you don't even need to use any apply utility in that case 馃槀

Yep, should be doable in userland without any API changes.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mickeyreiss-visor picture mickeyreiss-visor  路  3Comments

ms88privat picture ms88privat  路  3Comments

captbaritone picture captbaritone  路  3Comments

jbri7357 picture jbri7357  路  3Comments

cloudfroster picture cloudfroster  路  3Comments