- 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.
推薦閱讀
- Learning LibGDX Game Development(Second Edition)
- JavaScript前端開發模塊化教程
- The Complete Coding Interview Guide in Java
- 學習正則表達式
- Node Cookbook(Second Edition)
- 深入淺出Go語言編程
- Scala編程(第5版)
- .NET Standard 2.0 Cookbook
- 后臺開發:核心技術與應用實踐
- Natural Language Processing with Python Quick Start Guide
- SQL Server 入門很輕松(微課超值版)
- Learning Bootstrap 4(Second Edition)
- HTML5移動Web開發
- Three.js權威指南:在網頁上創建3D圖形和動畫的方法與實踐(原書第4版)
- Groovy 2 Cookbook