- 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.
- OpenDaylight Cookbook
- Java程序設計實戰教程
- Reactive Programming with Swift
- C語言程序設計實驗指導 (第2版)
- INSTANT Sinatra Starter
- Kotlin開發教程(全2冊)
- OpenMP核心技術指南
- Solutions Architect's Handbook
- Learning Nessus for Penetration Testing
- CodeIgniter Web Application Blueprints
- MySQL 8從零開始學(視頻教學版)
- PhoneGap 4 Mobile Application Development Cookbook
- Python一行流:像專家一樣寫代碼
- Java程序設計教程
- Visual Basic語言程序設計基礎(第3版)