[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 ...
随机推荐
- 新手学python-Day4-进制,数据类型,编码转换,列表
python3中字符串的编码转换 names=b'\xe2\x82\xac20'.decode('utf-8') print(names) names='€20'.encode('utf-8') pr ...
- UVALive - 2031 Dance Dance Revolution 三维dp
题目大意:有一个胖子在玩跳舞机.刚開始的位置在(0,0).跳舞机有四个方向键,上左下右分别相应1,2,3,4.如今有下面规则 1.假设从0位置移动到随意四个位置,消耗能量2 2.假设从非0位置跳到相邻 ...
- c#将List<T>转换成DataSet
/// <summary> /// List<T> 转换成DataSet /// </summary> /// &l ...
- oracle 11g sql developer安装后无法使用
oracle11g安装后出现 再去官网单独下来个sql developer安装 sql developer须要jre支持
- Linux防火墙限制指定port仅仅能由指定IP訪问
须要对redis的端口做限制,仅仅能让公司内指定IP的机器訪问 -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A ...
- Qt Quick 简单介绍
Qt Quick 是 Qt 提供的一种高级用户界面技术.使用它可轻松地为移动和嵌入式设备创建流畅的用户界面. 在 Android 设备上, Qt Quick 应用默认使用 OpenGL ES ,渲染效 ...
- 关于sql中的with(nolock)
SQL Server 中的 NOLOCK 究竟是什么意思 一般用于此类语句中:select * from t with(NOLOCK) nolock是不加锁查询.能够读取被事务锁定的数据,也称为脏读. ...
- 修改host文件浏览国外网站
公司电脑网络没法进github没办法工作需要只能FQ了. 方法1:用VPN 但是地要钱呐,没钱只能放弃了,不过每天试用还是可以的 方法2:改电脑host,文件中每条数据前面的#代表注释.把要访问的地址 ...
- html 移动端关于长按图片弹出保存问题
在做html5项目的时候有个需求是要拖动一个图片,但是又不要用户长时间按着弹出保存框.首先想到的就是在点图片的时候阻止默认事件的发生: js停止冒泡· function myfn(e){ window ...
- 【DNN】 安装问题
http://blog.csdn.net/hwt0101/article/details/9153083 这是IIS 注册的问题 IIS 在安装VS 之前就装上了,所以 没有注册是上 F4 从新卸载 ...