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. oracle数据库服务介绍

    共有7个服务,这七个服务的含义分别为: 1. Oracle ORCL VSS Writer Service:Oracle卷映射拷贝写入服务,VSS(Volume Shadow Copy Service ...

  2. 怎样更好的深入学习andorid

    把主要的控件  基本布局 基本组件  数据存储都熟悉一边,在看网络的时候,有点不知道怎么搞了.由于一直用c开发,但接触socket也不多,这两天把java的socket编程熟悉了下.找了非常多书,可是 ...

  3. ABAP FIELD-SYMBOLS 有大作用- 将没有可改參数的增强出口变得也能改主程序的值了

    看下图代码: report  z_xul_test2 中 定义了 全局变量 G_DATA1 , 分别调用了 z_xul_tes1 中的 form  和 function zbapi_test , 这两 ...

  4. PostgreSQL hstore 列性能提升一例

    PostgreSQL 支持hstore 来存放KEY->VALUE这类数据, 事实上也相似于ARRAY或者JSON类型.  要高效的使用这类数据,当然离不开高效的索引.我们今天就来看看两类不同的 ...

  5. 第一个python作业题目以及代码

    1. 编写程序,用户输入一个三位以上的整数,输出其百位以上的数字.例如用户输入1234,则程序输出12.(提示:使用整除运算.) x=input("请输入一个三位以上的数字:") ...

  6. iOS七种手势

    // 初始化一个UIimageView UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, ...

  7. C#的常见算法(面试)(转)

    一.求以下表达式的值,写出您想到的一种或几种实现方法: 1-2+3-4+……+m //方法一,通过顺序规律写程序,同时也知道flag标志位的重要性. static int F1(int m) { ; ...

  8. java高级——生产者消费者问题

    多线程是一个很重要的应用,本节讲述多线程中同步问题 public class ThreadDemo { public static void main(String[] args) { Resourc ...

  9. 如何防止js刷新页面后倒计时改变

    1.存入cookie或localstorage(清除浏览器缓存后时间依然改变) 2.存入数据库

  10. 预测一下web前端未来的6个趋势

    2018年前端技术的发展也将进入到一个相对稳定的阶段, 就前端主流技术框架的发展而言,过去的几年里发展极快,在填补原有技术框架空白和不足的同时也渐渐趋于成熟. 未来前端在已经趋向成熟的技术方向上面将会 ...