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

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

Implicit side-effects are hard to do

Side-effects in code that uses mutable data are implicit. Immutable.js, on the other hand, promotes explicit side-effects by placing them at the end of a method call chain. This makes the side-effects in your code easy to spot, and easy to reason our way through the sequence of transformations and persistent changes that lead up to the side-effect occurring.

Implicit side-effects are problematic because we don't have any meaningful way to track them. For example, you change some data that results in four function calls being made. Do any of them have side-effects? Two of them? All of them? Do the side-effects cascade into other side-effects? We're creating too much work for our brains to handle here.

The trick with Immutable.js is to make explicit the things that matter when you're reading code. This means quickly figuring out what caused a given side-effect to occur. On the other hand, you can't make everything explicit otherwise you'd have a mountain of code to sift through. The implicitness of Immutable.js comes with piecing together data by gluing it together using chaining—there's a lot going on behind the scenes that you don't need to think about.

主站蜘蛛池模板: 阿坝县| 谷城县| 通许县| 滁州市| 贵州省| 镇平县| 巧家县| 临漳县| 新田县| 达日县| 法库县| 广宗县| 平阳县| 祥云县| 交口县| 泌阳县| 广东省| 泸溪县| 奉节县| 盈江县| 天水市| 巴彦淖尔市| 获嘉县| 宝清县| 阿拉善右旗| 房山区| 屏山县| 奉新县| 宁波市| 子长县| 天柱县| 夏河县| 玛纳斯县| 汾阳市| 承德市| 蒙山县| 沙坪坝区| 阳新县| 芜湖县| 香港| 垫江县|