- MobX Quick Start Guide
- Pavan Podila Michel Weststrate
- 374字
- 2021-08-05 10:34:24
A note on observability
When you use the observable() API, MobX will apply deep observability to the observable instance. This means it will track changes happening to the observable object, array, or map and do it for every property, at every level. In the cases of arrays and maps, it will also track the additions and removals of entries. Any new entry in an array or a map is also made into a deep observable. This is definitely a great sensible default and works well for most situations. However, there will be cases where you may not want this default.
You can change this behavior at the time of creating the observable. Instead of using observable(), you can use the sibling APIs (observable.object(), observable.array(), observable.map()) to create the observable. Each of these takes an extra argument for setting options on the observable instance. Take a look at this:
observable.object(value, decorators, { deep: false });
observable.map(values, { deep: false });
observable.array(values, { deep: false });
By passing in { deep: false } as an option, you can effectively prune the observability just to the first level. This means the following:
For observable objects, MobX only observes the initial set of properties. If the value of property is an object, an array, or a map, it won't do any further observation.
For observable arrays, MobX only observes the addition and removal of items in the array. If an item is an object, an array, or a map, it won't do any further observation.
For observable maps, MobX only observes the addition and removal of items in the map. If the value of a key is an object, an array, or a map, it won't do any further observation.
Now, it is worth mentioning that observable() internally calls one of the preceding APIs and sets the option to { deep: true }. This is the reason observable() has deep observability.
- 面向物聯網的CC2530與傳感器應用開發
- 網絡故障現場處理實踐(第4版)
- Oracle SOA Suite 11g Performance Tuning Cookbook
- WordPress 5 Complete
- Wireshark網絡分析就這么簡單
- Mastering JavaFX 10
- 基于性能的保障理論與方法
- 語音信號處理及Blackfin DSP實現
- Learning Windows 8 Game Development
- 中國互聯網發展報告2021
- Getting Started with tmux
- 巧學活用CISCO網絡典型配置
- 萬物互聯:物聯網核心技術與安全
- CDN技術詳解
- 天下一家:網絡聯通世界(科學新導向叢書)