官术网_书友最值得收藏!

Data is only created

Let's revisit the visualization of data flowing from top to bottom, ending with a side-effect. Along the way, we're either changing the state of data with persistent changes, or we're shaping the data that we need using sequence transformations. From the beginning to the end of this flow, we're only creating new data.

The chained Immutable.js collection method calls result in new data—every time. This means that if we make a mistake and accidentally try to use data in a way that falls outside of the unidirectional flow that we're following, Immutable.js will protect us from ourselves. When this happens, the result is often a broken application that doesn't work. This is better than a half-working application that has mutability bugs hidden deep inside of it.

For example, suppose that we call set() on an immutable map to set a value, expecting that simply calling this method would be enough to change the state of the map. But since the set() method is a persistent change, it doesn't change the map—it creates and returns a new map. So while we weren't expecting this behavior, it's better than accidentally changing the state of something.

主站蜘蛛池模板: 赫章县| 广南县| 耿马| 左贡县| 汾阳市| 鄄城县| 五峰| 友谊县| 襄城县| 开江县| 大同市| 资溪县| 衡阳县| 高淳县| 古田县| 长垣县| 丹江口市| 金堂县| 谢通门县| 台北县| 吉木萨尔县| 苍南县| 永修县| 凤阳县| 休宁县| 沁源县| 海原县| 徐闻县| 阿拉善右旗| 满洲里市| 湖州市| 岑巩县| 晋江市| 河北省| 许昌县| 深泽县| 义马市| 河曲县| 禹城市| 台湾省| 齐齐哈尔市|