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

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

What other direction is there?

The best way to visualize unidirectional data flow is in a top-down fashion. Data starts in one state at the top, changes state as it flows downward, ending with a side-effect that does something with the data. When this is enforced as a property of the architecture, side-effects are predictable. We can easily trace the starting point of data, through the transformations it makes, ending with the visible side-effect.

When we don't enforce a unidirectional data flow, it's difficult to trace cause and effect. This is the main reason that Facebook started promoting the concept with the creation of Flux—to prevent components from changing state at will and passing the changed state on to another component. For example, let's say that you aren't using immutable data, and that one component changes its state in response to an event. Then some other component that references this state renders itself, causing its state to change as a result of the first change. These are nothing more than uncontrolled side-effects.

Immutable.js is a low-level library compared to the ideas of Flux or a UI component library such as React. Even if you're not using either of these, you can still leverage Immutable.js to build a unidirectional architecture.

主站蜘蛛池模板: 榆林市| 石屏县| 山阳县| 桦甸市| 宁化县| 法库县| 阜城县| 龙陵县| 肇庆市| 大安市| 清徐县| 惠州市| 台东市| 固始县| 朝阳区| 万盛区| 宜君县| 满城县| 义马市| 苗栗市| 胶南市| 康马县| 天长市| 筠连县| 肃北| 上虞市| 会东县| 台东县| 班玛县| 文安县| 卫辉市| 涞源县| 大洼县| 太谷县| 盘锦市| 沭阳县| 平湖市| 柳河县| 伊通| 陕西省| 麻江县|