Skip to content

How to add non immutable store when combining reducers #69

@kopax

Description

@kopax

Hi, thanks for redux-immutable.

I am trying to mix immutable reducer and classic reducer.

I have tried to tweak the combineReducer.js like this :

    if (inputState.withMutations) {
      return inputState.withMutations(function (temporaryState) {
        reducerKeys.forEach(function (reducerName) {
          var reducer = reducers[reducerName];
          var currentDomainState = temporaryState.get(reducerName);
          var nextDomainState = reducer(currentDomainState, action);

          (0, _utilities.validateNextState)(nextDomainState, reducerName, action);

          temporaryState.set(reducerName, nextDomainState);
        });
      });
    } else {
      reducerKeys.forEach(function (reducerName) {
        var reducer = reducers[reducerName];
        var currentDomainState = inputState[reducerName];
        var nextDomainState = reducer(currentDomainState, action);

        (0, _utilities.validateNextState)(nextDomainState, reducerName, action);

        inputState[reducerName] = nextDomainState;
      });
      return inputState;
    }

And mix my reducer like this

import { combineReducers } from 'redux';
import { combineReducers as combineReducersImmutable } from 'redux-immutable';

export default function createReducer(injectedReducers) {
  const immutableReducer = combineReducersImmutable({
    route: routeReducer,
    locale: localeReducer(),
    form: formReducer,
    ...injectedReducers,
  });
  const nonmutableReducer = combineReducers({
    admin: adminReducer,
  });
  return combineReducersImmutable({
    admin: adminReducer,
    route: routeReducer,
    locale: localeReducer(),
    form: formReducer,
    ...injectedReducers,
  }, () => {
    return {
      ...immutableReducer(undefined, { type: '' }),
      ...nonmutableReducer(undefined, { type: '' })
    };
  })
}

But that doesn't work very well. Any Idea how I could achieve this ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions