reduxjs / redux

A JS library for predictable global state management
https://redux.js.org
MIT License
60.88k stars 15.27k forks source link

about how to inject a middleware #2355

Closed alanwei0 closed 7 years ago

alanwei0 commented 7 years ago

in the docs of redux

If you use other store enhancers in addition to applyMiddleware, make sure to put applyMiddleware before them in the composition chain because the middleware is potentially asynchronous. For example, it should go before redux-devtools because otherwise the DevTools won't see the raw actions emitted by the Promise middleware and such.

if applyMiddleware must go before other enhancers, why not change the api of createStore, for example:

createStore(reducer, initialState, middlewares, enhancers);

then, users don't need to care about the order between applyMiddleware and other enhancers

markerikson commented 7 years ago

@alanwei0 : Because applyMiddleware is a store enhancer. It's just the only one that ships with Redux, but other than that there's nothing "special" about it. It's also possible that there might be some scenario where you might want to put another enhancer first (although I'm not sure of a specific example right now).