[MST] Defining Asynchronous Processes Using Flow
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的更多相关文章
- Using PL/SQL APIs as Web Services
Overview Oracle E-Business Suite Integrated SOA Gateway allows you to use PL/SQL application program ...
- NSOperationQueue 和 NSOperation
The NSOperationQueue class regulates the execution of a set of NSOperation objects. After being adde ...
- Comparison of programming paradigms
Main paradigm approaches[edit] The following are widely considered the main programming paradigms, a ...
- 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 ...
- iOS NSOperation的使用
先给出NSOpetation的官方指导https://developer.apple.com/library/ios/documentation/Cocoa/Reference/NSOperation ...
- ActiveMQ笔记——技术点汇总
目录 · Introduction to ActiveMQ · Installing ActiveMQ · Message-oriented middleware · JMS specificatio ...
- Build Telemetry for Distributed Services之OpenTracing简介
官网地址:https://opentracing.io/ What is Distributed Tracing? Who Uses Distributed Tracing? What is Open ...
- Asynchronous JS: Callbacks, Listeners, Control Flow Libs and Promises
非常好的文章,讲javascript 的异步编程的. ------------------------------------------------------------------------- ...
- SSIS Data Flow 的 Execution Tree 和 Data Pipeline
一,Execution Tree 执行树是数据流组件(转换和适配器)基于同步关系所建立的逻辑分组,每一个分组都是一个执行树的开始和结束,也可以将执行树理解为一个缓冲区的开始和结束,即缓冲区的整个生命周 ...
随机推荐
- Shell(二)运算符
基本运算符 Shell 和其他编程语言一样,支持多种运算符,包括: 算数运算符 关系运算符 布尔运算符 字符串运算符 文件测试运算符 原生bash不支持简单的数学运算,但是可以通过其他命令来实现,例如 ...
- python3 将两个列表生成一个字典
需求: 存在两个list如下 list1 = ["one", "two", "three"] list2 = ["1", ...
- STM32利用TIM3产生一个1--100Hz可调频率
目标:利用TIM3结合普通GPIO实现一个1--100HZ的可控频率,误差在0.5HZ以内 核心:要实现该功能首先要明确频率的定义,频率就是1秒内发生周期性变化的次数,例如一个正弦波,1S内,走了15 ...
- Mysql学习总结(34)——Mysql 彻底解决中文乱码的问题
mysql 中常常出现对中文支持不友好的情况 常见的错误 "Illegal mix of collations for operation" 下面我们规整一下 mysql 数据库中 ...
- java内存管理之垃圾回收及JVM调优
GC(garbage Collector 垃圾收集器)作用:a.内存的动态分配:b.垃圾回收注:Java所承诺的自动内存管理主要是针对对象内存的回收和对象内存的分配. 一.垃圾标记 程序计数器.Jav ...
- 洛谷 P2652 同花顺
P2652 同花顺 题目背景 所谓同花顺,就是指一些扑克牌,它们花色相同,并且数字连续. 题目描述 现在我手里有n张扑克牌,但它们可能并不能凑成同花顺.我现在想知道,最少更换其中的多少张牌,我能让这 ...
- 自己动手写shell命令之more
unix下more命令的简单实现: #include <stdio.h> #define PAGELEN 24 #define LINELEN 512 int do_more(FILE * ...
- window8.1 CenterOS 双系统
window8.1 CenterOS 双系统 学习了: http://blog.csdn.net/ac_hell/article/details/53436890 https://jingyan.ba ...
- 汇编 -- Hook API (MessageBoxW)
说到HOOK.我看了非常多的资料和教程.无奈就是学不会HOOK.不懂是我的理解能力差.还是你们说的 不够明确,直到我看了下面这篇文章,最终学会了HOOK: http://blog.sina.com.c ...
- mydumper安装及安装故障汇总
mydumper是针对mysql数据库备份的一个轻量级第三方的开源工具,备份方式术语逻辑备份.它支持多线程.备份速度远高于原生态的mysqldump以及众多优异特性. 因此该工具是DBA们的不二选 ...