[MST] Use Volatile State and Lifecycle Methods to Manage Private State
MST has a pretty unique feature: It allows you to capture private state on models, and manage this state by using lifecycle hooks. For example by setting up a WebSocket connection and disposing of the connection automatically as soon as the instance gets removed from the store. In this lesson, we will leverage cancellable fetches to abort in-flight requests when appropriate
In this lesson you will learn:
- Aborting window.fetch requests :-).
- Storing private, volatile, internal state in the function closure
- A second life-cycle hook: beforeDestroy
The whole point for this post is showing how to abort fetch request:
export const Group = types
.model({
users: types.map(User)
})
.actions(self => {
let controller return {
afterCreate() {
self.load()
},
load: flow(function* load() {
controller = window.AbortController && new window.AbortController()
try {
const response = yield window.fetch(`http://localhost:3001/users`, {
signal: controller && controller.signal
})
applySnapshot(self.users, yield response.json())
console.log("success")
} catch (e) {
console.log("aborted", e.name)
}
}),
reload() {
if (controller) controller.abort()
self.load()
},
beforeDestroy() {
if (controller) controller.abort()
}
}
})
https://developer.mozilla.org/en-US/docs/Web/API/AbortController
[MST] Use Volatile State and Lifecycle Methods to Manage Private State的更多相关文章
- LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: Root WebApplicationContext: startup date [Sun Jan 13 17:59:19 CST 2019]; root of context hierarch
在运行项目时出现了:LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via ...
- LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: --异常记录
升级了JDK之后,启动应用,直接抛出此异常.网上搜罗半天,没有正确的解决方案. 然后想到了是“升级了JDK”,重新检查所有JDK相关的配置的地方,在Debug Configurations里找到启动时 ...
- vue & lifecycle methods & this bug & ES6 Arrow function & this bind bug
vue & lifecycle methods & this bug ES6 Arrow function & this bind bug bad fetchTableData ...
- React LifeCycle Methods & re-learning 2019
React LifeCycle Methods & re-learning 2019 v16.9.0 https://reactjs.org/docs/react-component.html ...
- 执行bin/hdfs haadmin -transitionToActive nn1时出现,Automatic failover is enabled for NameNode at bigdata-pro02.kfk.com/192.168.80.152:8020 Refusing to manually manage HA state的解决办法(图文详解)
不多说,直接上干货! 首先, 那么,你也许,第一感觉,是想到的是 全网最详细的Hadoop HA集群启动后,两个namenode都是standby的解决办法(图文详解) 这里,nn1,不多赘述了.很简 ...
- Start state is missing. Add at least one state to the flow
springmvc配置过程中,会配置数据库文件,比如说如下文件:这个时候可能会出现“Start state is missing. Add at least one state to the flow ...
- PMD - Avoid autogenerated methods to access private fields and methods of inner / outer classes
PMD错误 Avoid autogenerated methods to access private fields and methods of inner / outer classes 样例 p ...
- springmvc.xml 中报错:Start state is missing. Add at least one state to the flow
最近一个学弟问我关于整合springMVC和spring出现的配置文件springmvc.xml出现的Start state is missing. Add at least one state to ...
- [MST] Create an Entry Form to Add Models to the State Tree
It is time to add new entries to the wishlist. We will achieve this by reusing forms and models we'v ...
随机推荐
- iText、poi操作word2007(读取,生成)
关于生成word文件以及插入文字.表格.图片等功能,我使用了poi和itext,因为poi插入图片的jar包我在网上查并不是太完全,也可能我没找到如何使用,所以插入图片我用的是itext iText所 ...
- sql查询语句中on和where的区别
sql中的连接查询分为3种, cross join,inner join,和outer join , 在 cross join和inner join中,筛选条件放在on后面还是where后面是没区别 ...
- MQTT学习
http://blog.csdn.net/mzwhhwj/article/details/77489890
- 洛谷 P1490 买蛋糕
P1490 买蛋糕 题目描述 野猫过生日,大家当然会送礼物了(咳咳,没送礼物的同志注意了哈!!),由于不知道送什么好,又考虑到实用性等其他问题,大家决定合伙给野猫买一个生日蛋糕.大家不知道最后要买的蛋 ...
- [using_microsoft_infopath_2010]Chapter3 表单设计基础:使用InfoPath布局,控件,和视图
本章概要 1.使用InfoPath的布局工具构建吸引人的表单 2.使用InfoPath表格工具 3.在表单上添加字段和控件 4.使用section和container组织表单里的控件 5.在一个表单上 ...
- android全磁盘加密
android 全磁盘加密 什么是全磁盘加密? 全磁盘加密是使用一个密钥来为android设备上全部的用户数据加密的过程.一旦设备被加密,全部的用户创建的数据都将会在提交的磁盘之前自己主动加密,在读取 ...
- JavaScript事件驱动机制&定时器机制
在浏览器中,事件作为一个极为重要的机制,给予JavaScript响应用户操作与DOM变化的能力.在NodeJS中.异步事件驱动模型则是提高并发能力的基础. 一.程序怎样响应事件 程序响应外部的事件有两 ...
- [NOI.AC#32]sort 构造
链接 50分做法(只有0,1) 根据归并排序的思想,假设我们现在已经把 \(l\dots mid\) 和 \(mid+1\dots r\) 排好序 只要把左边连续的1和右边连续的0翻转即可 inlin ...
- ORACLE RAC如何增加节点
ORACLE RAC系统是一个可以横向进行扩展的系统,当一个RAC系统计算能力不满足客户的需求时候,增加节点能够快速增加整个系统的计算能力,使得客户系统计算能力得到一定的提升,以满足客户不断增长的计算 ...
- Windows下本机简易监控系统搭建(Telegraf+Influxdb+Grafana)--转
原文地址:http://www.cnblogs.com/liugh/p/6683488.html 一.文件准备 1.1 文件名称 telegraf-1.2.1_windows_amd64.zip in ...