reactjs - updated nested Immutable in immutable.js -


how can update nested immutable map item without mutatiling whole tree ?

example :

var tree = map({  branch1:map([]),  branch2:map({ 1: map({id:1,value:'hello'}) }), }); 

how can update tree.branch2.1.value ?

will cause branch1 new copy ?

i'm using in reactjs redux app. since i'm using selectors, want change value of branch2 without changin branch1 also, selectors wonnt recalculate again

changing values in immutable.js object always return new object instead of mutating it. that's whole point of library. if worried unnecessary re-renders based on other aspects of state changing, should use shouldcomponentupdate lifecycle method ensure components update when value of part of app state changes, , not when new object.

for case, make sense use setin method immutable maps.

tree.setin(['branch2', 1, 'value'], 'newvalue'); 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -