gajus / redux-immutable

redux-immutable is used to create an equivalent function of Redux combineReducers that works with Immutable.js state.
Other
1.88k stars 82 forks source link

reducer is not a function #40

Closed sarink closed 8 years ago

sarink commented 8 years ago

I keep running into the error reducer is not a function.

Not sure what I'm doing wrong? My state is a plain object and some of the keys within state are Immutable

redux/modules/rootReducer.js:

import { combineReducers } from 'redux-immutable';
import { routeReducer } from './routeReducer';

export default combineReducers({
  routing: routeReducer,
});

redux/modules/routeReducer.js:

import Immutable from 'immutable';
import { LOCATION_CHANGE } from 'react-router-redux';

const initialState = Immutable.fromJS({
  locationBeforeTransitions: null
});

const locationChangeReducer = (state, action) => {
  return Object.assign({}, state, {locationBeforeTransitions: action.payload});
};

export default function routeReducer(state = initialState, action) {
  switch (action.type) {
    case LOCATION_CHANGE: return locationChangeReducer(state, action);
    default: return state;
  }
}

redux/createStore.js:

import { createStore as _createStore, applyMiddleware, compose } from 'redux';
import createMiddleware from './middleware/clientMiddleware';
import { routerMiddleware } from 'react-router-redux';
import reducer from './modules/reducer';
import { persistState } from 'redux-devtools';
import { DevTools } from 'containers';

export default function createStore(history, client, data) {
  // Sync dispatched route actions to the history
  const reduxRouterMiddleware = routerMiddleware(history);

  const middleware = [createMiddleware(client), reduxRouterMiddleware];

  let finalCreateStore;
  if (_DEVELOPMENT__ && __CLIENT__ && __DEVTOOLS__) {
    finalCreateStore = compose(
      applyMiddleware(...middleware),
      window.devToolsExtension ? window.devToolsExtension() : DevTools.instrument(),
      persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/))
    )(_createStore);
  } else {
    finalCreateStore = applyMiddleware(...middleware)(_createStore);
  }

  const store = finalCreateStore(reducer, data);

  if (__DEVELOPMENT__ && module.hot) {
    module.hot.accept('./modules/reducer', () => {
      store.replaceReducer(reducer);
    });
  }

  return store;
}
gajus commented 8 years ago

Duplicate of https://github.com/gajus/redux-immutable/issues/38