- MobX Quick Start Guide
- Pavan Podila Michel Weststrate
- 168字
- 2021-08-05 10:34:24
Observable maps
You can make an observable map with the observable.map() API. In principle, it works the same way as observable.array() and observable.object(), but it is meant for ES6 Maps. The observable map instance shares the same API as a regular ES6 Map. Observable maps are great for tracking dynamic changes to the keys and values. This is in stark contrast to observable objects, which do not track properties that are added after creation.
In the following code example, we are creating a dynamic dictionary of Twitter-handles to names. This is a great fit for an observable map, as we are adding keys after creation. Take a look at this code block:
import { observable } from 'mobx';
// Create an Observable Map
const twitterUserMap = observable.map();
console.log(twitterUserMap.size); // Prints: 0
// Add keys
twitterUserMap.set('pavanpodila', 'Pavan Podila');
twitterUserMap.set('mweststrate', 'Michel Weststrate');
console.log(twitterUserMap.get('pavanpodila')); // Prints: Pavan Podila
console.log(twitterUserMap.has('mweststrate')); // Prints: Michel Weststrate
twitterUserMap.forEach((value, key) => console.log(`${key}: ${value}`));
// Prints:
// pavanpodila: Pavan Podila
// mweststrate: Michel Weststrate
推薦閱讀
- 網絡教育學習指導
- 網絡協議工程
- 物聯網短距離無線通信技術應用與開發
- 智能網聯汽車V2X與智能網聯設施I2X
- 物聯網檢驗檢測技術
- 物聯網概論(第2版)
- 互聯網基礎資源技術與應用發展態勢(2021—2023)
- Go Web Scraping Quick Start Guide
- Building RESTful Web Services with Spring 5(Second Edition)
- 中國互聯網發展報告2018
- Microservice Patterns and Best Practices
- 網絡環境中基于用戶視角的信息質量評價研究
- Windows Server 2012 Hyper-V虛擬化管理實踐
- 通信十年:擁抱互聯網
- 5G技術與標準