Files
knowledge-kit/Chapter2 - Web FrontEnd/2.36.md
2020-02-25 17:46:51 +08:00

16 lines
647 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# immutable.jS 与 React
## 引用带来副作用
js 中数据类型分为2种primitive value 和 Object。js 中的对象非常灵活,某个地方对对象进行修改后产生的结果难以预期,所以我们需要不可变对象。
但是自己实现的对象拷贝算法,可能浪费时间也浪费空间, 所以诞生了 immutable.js 这个库。
## 核心实现
immutable.js 基于哈希映射树和 vector map tries。只 clone 该节点和其祖先节点,其他保持不变,这样可以共享大部分相同的节点,大大提高性能。
1. 避免直接修改线性结构
2. 减小内存开销(增量更新)