erikras / multireducer

A utility to wrap many copies of a single Redux reducer into a single key-based reducer.
MIT License
422 stars 23 forks source link

After including the multireducer the actions dissaper #110

Closed HorseBinky closed 7 years ago

HorseBinky commented 8 years ago

Greetings!

First of all the multireducer lib is exactly what I'am looking for to reuse some of my containers. But after I included the multireducer and adapted our code to your examples, the actions became undefined. I use React-redux 4.4.2, Redux 3.5.2 and React 15. The problem appears during the LOCATION_CHANGE.action while loding the page. It seems that the system crash inside the combineReducer where the multireducer is included. Here is an example of my code:

Reducers:

const reducer = combineReducers({
  listCollection: multireducer({
    list1: list,
    list2: list,
  })
});

action:

export function listInit(initData) {
  return {
    type: types.LIST_INIT,
    initData,
  };
}

reducer:

export default function list(state = initialState, action) {
// Here is the problem: action is undefined
  switch (action.type) {
    case types.LIST_INIT:
      return {
        data: action.initData,
        orgData: action.initData,
        ...state,
      }; .....

Thanks for your help!!

yesmeck commented 8 years ago

Hello, I'm working on a new version of multireducer, could you try the new version and see if the problem still exists?

gsccheng commented 8 years ago

I am having a similar problem and it still exists after using multireducer v3.0.0. Empty objects are being passed as actions to the multireducer reducers but seems to be passed appropriately to non-multireducer reducers. However, multireducer works if I'm not using reduxAsyncConnect and promises so it can be from the way that is set up.

gsccheng commented 8 years ago

Nevermind, it turns out dispatch needed a multireducer key, and I did it using wrapDispatch.