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
Post a Comment