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

  • 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.

主站蜘蛛池模板: 肥城市| 蓬安县| 平和县| 伽师县| 岳阳县| 东乡族自治县| 廉江市| 石河子市| 武胜县| 淮滨县| 将乐县| 纳雍县| 兴仁县| 屏山县| 北海市| 县级市| 滦南县| 浮梁县| 扎赉特旗| 博白县| 襄樊市| 吴川市| 奉化市| 朔州市| 岫岩| 朝阳县| 扎赉特旗| 阳原县| 石嘴山市| 南投市| 教育| 会泽县| 眉山市| 邯郸市| 文登市| 葵青区| 罗甸县| 西宁市| 衡东县| 洛阳市| 三河市|