- 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 Scala Programming
- JavaScript前端開發(fā)模塊化教程
- Spring 5.0 By Example
- Python數(shù)據(jù)可視化:基于Bokeh的可視化繪圖
- Java高并發(fā)核心編程(卷2):多線程、鎖、JMM、JUC、高并發(fā)設計模式
- Python王者歸來
- 數(shù)據(jù)結(jié)構(gòu)案例教程(C/C++版)
- Express Web Application Development
- 鴻蒙OS應用編程實戰(zhàn)
- Serverless Web Applications with React and Firebase
- 區(qū)塊鏈架構(gòu)之美:從比特幣、以太坊、超級賬本看區(qū)塊鏈架構(gòu)設計
- Python 快速入門(第3版)
- JavaScript Unit Testing
- RESTful Web API Design with Node.js(Second Edition)
- Instant AppFog