-
Notifications
You must be signed in to change notification settings - Fork 0
ImmutableJS
arthur791004 edited this page Sep 16, 2017
·
1 revision
- mutable: 可以修改的
- immutable: 不可修改的
- 可以修改的 object ,在 project 變得日益龐大的時候會變得很複雜
- Side Effect
-
Object.assign
在 object 比較複雜的情況下,效能會變差 - shallow copy
- deep cody
- Persistent Data Structure
- Structural Sharing
- 當某個節點 update 時,不會整份 copy ,只會更新需要變動的部分
import { Map } from 'immutable';
const a = Map({
select: 'users',
filter: Map({ name: 'Cam' })
})
const b = a.set('select', 'people');
a === b; // false
a.get('filter') === b.get('filter'); // true
- 讓程式變得更單純
- 節省記憶體
- Map ===> Object
- List ===> Array
- Set ===> 沒有順序且不可重複的 Array