uptrend-tech / uptrend-redux-modules

Collection of modules useful to redux based react apps.
MIT License
5 stars 1 forks source link

Warn that entities middleware needs to be before redux-saga-thunk #34

Open orther opened 6 years ago

orther commented 6 years ago

To be able to return the normalized (entities) results in the redux-saga-thunk promise the entities middleware needs to be before the redux-saga-thunk middleware. Otherwise the entities middleware isn't called until after the redux-saga-thunk middle returns results.

Ideally we could add a check that would warn if the middlewares were out of order.

The following code examples are from a project using URM that I updated to get the entities values in promise returned from action request.

Previous (Not Working)

export default [
  ReduxSagaThunk,
  ReduxThunk,
  routerMiddleware(browserHistory),
  // NOTE: ^^-- above reducers must be first and in order

  // redux-modules
  entities,
];

Updated (Working)

export default [
  // redux-modules
  entities,

  // following middleware must be in this order
  ReduxSagaThunk,
  ReduxThunk,
  routerMiddleware(browserHistory),
];