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.

  1. import { types, flow } from "mobx-state-tree"
  2.  
  3. import { WishList } from "./WishList"
  4.  
  5. const User = types
  6. .model({
  7. id: types.string,
  8. name: types.string,
  9. gender: types.enumeration("gender", ["m", "f"]),
  10. wishList: types.optional(WishList, {})
  11. })
  12. .actions(self => ({
  13. getSuggestions: flow(function* getSuggestions() {
  14. const response = yield window.fetch(`http://localhost:3001/suggestions_${self.gender}`)
  15. self.wishList.items.push(...(yield response.json()))
  16. })
  17. }))
  18.  
  19. export const Group = types.model({
  20. users: types.map(User) // similar to object entities
  21. })

[MST] Defining Asynchronous Processes Using Flow的更多相关文章

  1. Using PL/SQL APIs as Web Services

    Overview Oracle E-Business Suite Integrated SOA Gateway allows you to use PL/SQL application program ...

  2. NSOperationQueue 和 NSOperation

    The NSOperationQueue class regulates the execution of a set of NSOperation objects. After being adde ...

  3. Comparison of programming paradigms

    Main paradigm approaches[edit] The following are widely considered the main programming paradigms, a ...

  4. Model-View-ViewModel (MVVM) Explained 转摘自:http://www.wintellect.com/blogs/jlikness/model-view-viewmodel-mvvm-explained

    The purpose of this post is to provide an introduction to the Model-View-ViewModel (MVVM) pattern. W ...

  5. iOS NSOperation的使用

    先给出NSOpetation的官方指导https://developer.apple.com/library/ios/documentation/Cocoa/Reference/NSOperation ...

  6. ActiveMQ笔记——技术点汇总

    目录 · Introduction to ActiveMQ · Installing ActiveMQ · Message-oriented middleware · JMS specificatio ...

  7. Build Telemetry for Distributed Services之OpenTracing简介

    官网地址:https://opentracing.io/ What is Distributed Tracing? Who Uses Distributed Tracing? What is Open ...

  8. Asynchronous JS: Callbacks, Listeners, Control Flow Libs and Promises

    非常好的文章,讲javascript 的异步编程的. ------------------------------------------------------------------------- ...

  9. SSIS Data Flow 的 Execution Tree 和 Data Pipeline

    一,Execution Tree 执行树是数据流组件(转换和适配器)基于同步关系所建立的逻辑分组,每一个分组都是一个执行树的开始和结束,也可以将执行树理解为一个缓冲区的开始和结束,即缓冲区的整个生命周 ...

随机推荐

  1. 一个学习scrapy的网站

    当然是scrapy中文网辣,从浅到深,例子报错几乎都有 http://www.scrapyd.cn/doc/

  2. ucore_lab1

    练习1:理解通过make生成执行文件的过程.(要求在报告中写出对下述问题的回答) 实验过程 静态分析代码. 实验的目录结构如下: . ├── boot ├── kern │   ├── debug │ ...

  3. STM32使用HAL库实现ADC单通道转换

    STM32的ADC转换还是很强大的,它具有多个通道选择,这里我就不细说,不了解的可以自行百度,这里只是选取单通道,实现ADC转换.在文章开始之前,我说一下数据左对齐跟右对齐的差别,以前一直糊里糊涂的, ...

  4. SpringCloud 构建微服务架构-练习

    我使用的springboot的版本为2.0.2.RELEASE,这里概念性的东西我就不粘贴复制了,百度一下 都是 一.启动Eureka注册中心服务 1.新建springboot项目,pom.xml配置 ...

  5. mybatis中sql标签和include标签

    1.首先定义一个sql标签,一定要定义唯一id.(name,age是要查询的字段) <sql id="Base_Column_List" >name,age</s ...

  6. POJ——T2186 Popular Cows || 洛谷——P2341 [HAOI2006]受欢迎的牛

    http://poj.org/problem?id=2186 || https://www.luogu.org/problem/show?pid=2341 Time Limit: 2000MS   M ...

  7. EOSS V3.0.2 企业运营支撑系统(基于RBAC原理的权限管理)

    下载地址:https://github.com/jelly-liu/EOSS 一:EOSS 功能介绍 其于用户,角色,权限,资源(即菜单)的一套"简约有用"的权限管理系统,可在其基 ...

  8. MongoDB数据模型和索引学习总结

    MongoDB数据模型和索引学习总结 1. MongoDB数据模型: MongoDB数据存储结构: MongoDB针对文档(大文件採用GridFS协议)採用BSON(binary json,採用二进制 ...

  9. java ee5的新特性

    1.标注 一种元数据,作用分为三类:编写文档@Document.代码分析@Deparecated(过时的)和编译检查@override(重写) 2.EJB3 EJB2的升级版,商业化的java bea ...

  10. cocos2d-x 3.0的坑有哪些

    问题一:setup.py 之后, ANT文件夹为什么创建不成功? ANT文件夹要指定到bin以下,NDK和SDK则指定要根文件夹就可以 问题二:cocos run -p android 之后,执行应用 ...