- Architecting Angular Applications with Redux,RxJS,and NgRx
- Christoffer Noring
- 187字
- 2021-08-27 19:56:18
The store – managing state, data retrieval, and callbacks
It's easy to think of the store as the place where our data lives. That is, however, not all it is. What the store's responsibilities are can be expressed by this list:
- Holder of state
- Manages the state, able to update it if need be
- Able to handle side effects such as fetching/persisting data through HTTP
- Handles callbacks
As you can see, that is a bit more than just storing the state. Let's now reconnect to what we were doing when we set up a listener with the dispatcher. Let's move that code into our store file, store.js, and let's persist our message content in our store:
// store.js
let store = {};
function selectIndex(index) {
store["selectedIndex"] = index;
}
dispatcher.register(message => {
switch (message.type) {
case "SELECT_INDEX":
selectIndex(message.data);
break;
}
});
OK, so now the store is being told about the new index, but an important piece is missing, how do we tell the UI? We need a way to tell the UI that something has changed. A change means that the UI should reread its data.
推薦閱讀
- 智慧城市:大數據、互聯網時代的城市治理(第4版)
- 黑客攻防實戰技術完全手冊:掃描、嗅探、入侵與防御
- Wireshark網絡分析就這么簡單
- Yii Application Development Cookbook(Second Edition)
- Getting Started with Grunt:The JavaScript Task Runner
- Spring 5.0 Projects
- 面向5G-Advanced的關鍵技術
- 計算機網絡技術及應用
- 網絡安全應急響應技術實戰指南
- 互聯網+思維與創新:通往未來的+號
- Learning Node.js Development
- 物聯網與智慧農業
- 趣話通信:6G的前世、今生和未來
- 網絡攻防技術與實踐
- 夢工廠之沸騰關鍵幀:Maya動畫手冊