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
})

最新文章

  1. HTML 学习笔记 CSS(表格)
  2. python无意中发现的
  3. 101个LINQ示例,包含几乎全部操作
  4. CentOS 配置本地yum源
  5. APK文件安装模拟器和ADB命令的使用
  6. Windows Phone 8初学者开发—第21部分:永久保存Wav音频文件
  7. HDU 5366 The mook jong
  8. 腾讯云微计算实践:从Serverless说起,谈谈边缘计算的未来
  9. Lucene总结
  10. LindDotNetCore~授权中间件的介绍
  11. Java核心知识盘点(三)- 框架篇-Spring
  12. 吴恩达机器学习笔记6-梯度下降II(Gradient descent intuition)--梯度下降的直观理解
  13. JSP本质的理解(浏览器调试,response里面的文本都是out.write写入网络流)
  14. 【SDOI2017】数字表格
  15. python3模块: uuid
  16. Node.js之Express三
  17. hdu 4536 dfs
  18. 后端编程语言PHP
  19. Hystrix的用法
  20. php文件

热门文章

  1. Mysql学习总结(35)——Mysql两千万数据优化及迁移
  2. ASP.NET-Active Direcotry编程示例
  3. Activity嵌套多个Fragment实现横竖屏切换
  4. Oracle 学习笔记 14 -- 集合操作和高级子查询
  5. NYOJ 815 三角形【海伦公式】
  6. jqMobi(App Framework)入门学习(一)
  7. dll开发
  8. POJ 2190 模拟
  9. sqlserver如何给某一用户分配只能查看某一视图的权限
  10. 003.JMS概述