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

  • Mastering Immutable.js
  • Adam Boduch
  • 201字
  • 2021-07-08 10:30:04

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.

主站蜘蛛池模板: 马关县| 咸宁市| 隆林| 丹巴县| 敦化市| 贺兰县| 崇明县| 弥勒县| 西和县| 星座| 崇左市| 五寨县| 孟津县| 新兴县| 清原| 阿荣旗| 德化县| 宁南县| 托里县| 原平市| 公主岭市| 上栗县| 雷州市| 白玉县| 英山县| 光山县| 镇巴县| 榆中县| 博兴县| 剑河县| 永泰县| 崇信县| 通化县| 呼图壁县| 璧山县| 伊宁市| 岳池县| 卢氏县| 涪陵区| 安丘市| 嘉黎县|