[MST] Defining Asynchronous Processes Using Flow
Using Flow Asynchronous processes MST
2023-09-14 09:00:50 时间
In real life scenarios, many operations on our data are asynchronous. For example, because additional recourses need to get fetched. MST has first class support for asynchronous actions. We will start with a naively implemented async process, and work through async / await towards MST flows and generators.
In this lesson, you will learn
- That async process is painful if they need to respect the 'only actions can modify' semantics of MST
- Flows are the idiomatic way to describe async processes in MST
- Flows are robust; they make it possible to get full control over the lifecycle of a process
The whole point is to using 'flow( function* generatorFn() => {})' to fix some limitation.
import { types, flow } from "mobx-state-tree" import { WishList } from "./WishList" const User = types .model({ id: types.string, name: types.string, gender: types.enumeration("gender", ["m", "f"]), wishList: types.optional(WishList, {}) }) .actions(self => ({ getSuggestions: flow(function* getSuggestions() { const response = yield window.fetch(`http://localhost:3001/suggestions_${self.gender}`) self.wishList.items.push(...(yield response.json())) }) })) export const Group = types.model({ users: types.map(User) // similar to object entities })
相关文章
- ORSIm:A Novel Object Detection Framework in Optical Remote Sensing Imagery Using Spatial-Feature
- using polyglot JPEGs bypass CSP 分析
- GitHub推送报错:You‘re using an RSA key with SHA-1, which is no longer allowed
- ORA-28408: encryption using passphrase failed ORACLE 报错 故障修复 远程处理
- ORA-29814: expecting USING or DEFAULT keyword ORACLE 报错 故障修复 远程处理
- ORA-29827: keyword USING is missing ORACLE 报错 故障修复 远程处理
- ORA-31164: cannot load object-relational XML attribute using direct path ORACLE 报错 故障修复 远程处理
- MySQL Error number: MY-011243; Symbol: ER_XPLUGIN_USING_SSL_FOR_TLS_CONNECTION; SQLSTATE: HY000 报错 故障修复 远程处理
- Using MySQL with C: Fast and Easy Programming(mysqlforc)
- Exploring the Benefits of Using Linux and OTF for Streamlined Software Development.(linuxotf)
- Exploring the World of Linux with Ease: A Guide to Using 遨游 Browser(遨游forlinux)
- Exploring the Benefits of Using MySQL Views in Data Management(mysql视图有什么用)
- Exploring the Benefits of Using Linux LDAP for Secure and Efficient User Management(linuxldap)
- Exploring the Possibilities: Using Linux to Connect and Control HDMI Inputs(linuxhdmi输入)
- Flow技术在Oracle中的活用(flow在oracle)