Immutable-js: Map/List.constructor vs merge vs. set and ReactElements

Created on 25 Mar 2015  路  4Comments  路  Source: immutable-js/immutable-js

I'm a bit unclear about the expected behavior with Map/List.merge when the values are ReactElements (or nested non-function Objects in general).

var div = React.createElement('div', null);
var span = React.createElement('span', null);
var map = Immutable.Map({ reactElement: div });

map = map.set("reactElement", span);

React.render(map.get("reactElement"), document.body);

The above works fine...but if we use merge:

var div = React.createElement('div', null);
var span = React.createElement('span', null);
var map = Immutable.Map({ reactElement: div });

map = map.merge({ reactElement: span });

React.render(map.get("reactElement"), document.body);
//(Throws an error...this isn't a proper reactElement anymore);

So it seems like the Map.constructor assigns the key 'reactElement' to the object reference, and set update the existing reference a new one, but merge is (I assume) recursively serializing the updated key-values with fromJS? Is this expected, or is there no way to say merge shallow object references?

bug help wanted

Most helpful comment

This actually seems like a real issue to me, so I'm going to re-open. merge should be a shallow operation, mergeDeep needs to be used explicitly to do deeper merges.

All 4 comments

Nevermind I see that the problem is because I should be doing:

map = map.merge(Immutable.Map({ reactElement: span }));

This actually seems like a real issue to me, so I'm going to re-open. merge should be a shallow operation, mergeDeep needs to be used explicitly to do deeper merges.

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.

Merging this into #1293 which specifically highlighted the remaining issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jamesgpearce picture jamesgpearce  路  4Comments

evenstensberg picture evenstensberg  路  4Comments

papercuptech picture papercuptech  路  4Comments

coodoo picture coodoo  路  3Comments

kopax picture kopax  路  3Comments