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

[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. STM32 USB转串口驱动安装不成功出现黄色感叹号解决方法!

    相信很多人在做USB转串口时出现过串口驱动安装不成功,出现黄色感叹号问题, 出现这种问题一般是驱动安装不成功造成的. 这里我就这个问题总结几个简单的方法. 方法1: 插上USB,利用驱动人生安装驱动. ...

  2. Oracle expdp导出多表或表中的部分数据

    http://blog.itpub.net/16582684/viewspace-755072/

  3. C#-C#6.0新特性

    来自为知笔记(Wiz)

  4. scrapy研究探索(二)——爬w3school.com.cn

    下午被一个问题困扰了好一阵.终于使用还有一种方式解决. 開始教程二.关于Scrapy安装.介绍等请移步至教程(一)(http://blog.csdn.net/u012150179/article/de ...

  5. LIVE555研究之五:RTPServer(二)

    port是一样的. DynamicRTSPServer 继承关系: Medium是非常多类的基类.内部定义了指向环境类的引用和一个char类型媒体名称.并定义了依照媒体名称,查找相应媒体的成员函数lo ...

  6. Gradle 编译多个project(包括多Library库project依赖)指导

    Gradle Android最新自己主动化编译脚本教程(提供demo源代码) 这篇文章我简单写了基于Gradle2.1 进行的android project和android library的编译实例, ...

  7. [linux]shell中,反引號(`)的应用

    反引號位 (`) 位于键盘的Tab键的上方.1键的左方.注意与单引號(')位于Enter键的左方的差别. 反引號位 (`)在Linux中起着命令替换的作用. 命令替换是指shell可以将一个命令的标准 ...

  8. oracle 11g sql优化之行迁移处理(加大BLOCK块)

    行链接 产生原因:当一行数据大于一个数据块,ORACLE会同时分配两个数据块,并在第一个块上登记第二个块的地址,从而形成行链接. 预防方法:针对表空间扩大数据块大小.检查:analyze table ...

  9. spm总体说明

    目录 1.如何工作 2.何时使用 1.如何工作 sql plan baseline 是一个关联sql 语句的对象,设计会影响查询优化器生成执行计划,更具体的说,一个sql baseline包含其中的一 ...

  10. ikbc 时光机 F87 Ctrl 失灵 解决办法

    多按几次Fn+PrtSc,直至按键无错位.