- Mastering Immutable.js
- Adam Boduch
- 126字
- 2021-07-08 10:30:09
Parsing complex structures
The real power of the fromJS() function is its ability to turn complex JavaScript objects into complex immutable collections:
const myMap = fromJS({
a: {
b: ['c', 'd'],
e: {
f: 'g',
h: 'i'
}
}
});
console.log(
'myMap nested list',
myMap.getIn(['a', 'b']).toJS()
);
// -> myMap nested list [ 'c', 'd' ]
console.log('myMap nested value', myMap.getIn(['a', 'b', 1]));
// -> myMap nested value d
The fromJS() function will recursively transform native JavaScript structures into their immutable counterparts; this means for both lists and maps. One use case for this function is when the initial data that your application uses is based on JSON data, and you need a way to translate it into Immutable.js collections. Without fromJS(), this would be deceptively difficult.
推薦閱讀
- DevOps:軟件架構師行動指南
- LabVIEW Graphical Programming Cookbook
- ASP.NET Core 5.0開發入門與實戰
- 深入理解Django:框架內幕與實現原理
- 深入淺出WPF
- 精通Scrapy網絡爬蟲
- RISC-V體系結構編程與實踐(第2版)
- Visual Basic程序設計上機實驗教程
- 零基礎學Kotlin之Android項目開發實戰
- Mastering C++ Multithreading
- 網絡數據采集技術:Java網絡爬蟲實戰
- Python數據可視化之美:專業圖表繪制指南(全彩)
- 測試架構師修煉之道:從測試工程師到測試架構師
- 深入解析Java編譯器:源碼剖析與實例詳解
- 程序員的成長課