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

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.

主站蜘蛛池模板: 崇文区| 思南县| 大城县| 中超| 拜城县| 团风县| 门源| 重庆市| 黄梅县| 买车| 株洲县| 乡宁县| 怀集县| 手机| 滦南县| 西丰县| 邻水| 阳城县| 西华县| 宜兰县| 绍兴市| 尼勒克县| 彝良县| 沛县| 晋州市| 连城县| 梁平县| 旬阳县| 安顺市| 深水埗区| 原阳县| 阳东县| 神农架林区| 广昌县| 苍溪县| 沈阳市| 西乌珠穆沁旗| 安溪县| 全椒县| 斗六市| 富源县|