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

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.

主站蜘蛛池模板: 仁寿县| 汝城县| 凤庆县| 宝清县| 荥阳市| 宜昌市| 靖江市| 杭州市| 健康| 西吉县| 商洛市| 托克逊县| 霍林郭勒市| 大宁县| 郎溪县| 永安市| 武山县| 黔西县| 永福县| 奉贤区| 黄石市| 简阳市| 双峰县| 嵩明县| 定兴县| 龙川县| 广丰县| 木兰县| 称多县| 沾益县| 会同县| 基隆市| 岱山县| 老河口市| 盐源县| 特克斯县| 屯昌县| 广河县| 讷河市| 延吉市| 九龙县|