admin管理员组文章数量:1406911
I'm working on a flux application and am considering adopting immutable.js to maintain state. I saw that react supplies its own helper for updating immutable objects (.html), but couldn't tell how it was much different from immutable's own setIn and updateIn methods (i.e, i can already pare objects with === to se if they changes with setIn). Is there a reason to use the react helper with immutable.js? Is it just syntactic sugar?
TL;DR is:
var map = Immutable.fromJS({bar: 'baz'});
map2 = React.addons.update(map, {
bar: {$set: 'foo'}
});
different from
var map = Immutable.fromJS({bar: 'baz'});
map2 = map.set('bar', 'foo');
I'm working on a flux application and am considering adopting immutable.js to maintain state. I saw that react supplies its own helper for updating immutable objects (http://facebook.github.io/react/docs/update.html), but couldn't tell how it was much different from immutable's own setIn and updateIn methods (i.e, i can already pare objects with === to se if they changes with setIn). Is there a reason to use the react helper with immutable.js? Is it just syntactic sugar?
TL;DR is:
var map = Immutable.fromJS({bar: 'baz'});
map2 = React.addons.update(map, {
bar: {$set: 'foo'}
});
different from
var map = Immutable.fromJS({bar: 'baz'});
map2 = map.set('bar', 'foo');
Share
Improve this question
asked Dec 4, 2014 at 4:09
FensterFenster
3403 silver badges9 bronze badges
1 Answer
Reset to default 8React.addons.update
does not work with Immutable.js values; it works with plain JavaScript objects and arrays.
var map = { bar: 'baz' };
var map2 = React.addons.update(map, {
bar: {$set: 'foo'}
});
console.log(map2); // A plain JS object of value `{bar: 'foo'}`
The types in Immutable.js are implemented using special data structures for performance and space benefits; the plain JavaScript objects consumed and produced by React.addons.update, obviously, are not.
本文标签: javascriptUsing React39s immutable helper with ImmutablejsStack Overflow
版权声明:本文标题:javascript - Using React's immutable helper with Immutable.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744995497a2636646.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论