Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OBSERVATION: fromJS in combineReducers not successfully converting to Map in node (but works in browser) #37

Open
AshCoolman opened this issue Jan 5, 2018 · 0 comments

Comments

@AshCoolman
Copy link

Observation

Problem

Note: using immutable ^3.8.1

Creating store works fine in browser.

But in node v9.2.0 test environment, combineReducers was complaining that finalReducers.filter is not a function.

TypeError: finalReducers.filter is not a function

at combineReducers (node_modules/redux-immutablejs/lib/utils/combineReducers.js:83:33)

Research

I instrumented combineReducers thus:

// redux-immutablejs/lib/utils/combineReducers.js
function combineReducers(reducers) {
  var finalReducers = isImmutable(reducers) ? reducers : _immutable2['default'].fromJS(reducers);
  console.log(`

    reducers was a ${typeof reducers}
    reducers ${isImmutable(reducers) ? 'is' : 'is not' } immutable
    reducers keys: ${Object.keys(reducers).length}

    finalReducers is a ${typeof finalReducers}
    finalReducers ${_immutable2['default'].Map.isMap(finalReducers) ? 'is' : 'is not'} a Map
    fromJS(finalReducers) is a ${
      _immutable2['default'].Map.isMap(
        _immutable2['default'].fromJS(reducers)
      )
      ? 'Map' 
      : _immutable2['default'].List.isList(
        _immutable2['default'].fromJS(reducers)
      )
      ? 'List'
      : 'not list or map?'
    }
    `      
  )
  finalReducers = finalReducers.filter(function (v) {
    return typeof v === 'function';
  });
// ...

Browser (Chrome) output:

      reducers was a object
      reducers is not immutable
      reducers keys: 29


      finalReducers is a object
      finalReducers is a Map

On node v9.2.0 Error

      reducers was a object
      reducers is not immutable
      reducers keys: 29


      finalReducers is a object
      finalReducers is not a Map

Work-around

I just convert to map before I pass into combineReducers

Naive suggestion

It must be something to do with the node environment (babel?). But perhaps for safety's sake:

var finalReducers = isImmutable(reducers) ? reducers : _immutable2['default'].fromJS(reducers);

could be changed to:

  var finalReducers = isImmutable(reducers) ? reducers : _immutable2['default'].Map(reducers);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant