[RxJS] `add` Inner Subscriptions to Outer Subscribers to `unsubscribe` in RxJS
When subscribers create new "inner" sources and subscriptions, you run the risk of losing control of them when the outer subscriber unsubscribes. This is handled easily enough if you use the add method from the Subscriber class to add the "inner" subscription to the Subscriber.
class MyConcatMapSubscriber extends Subscriber {
innerSubscription
buffer = []
constructor(sub, fn) {
super(sub)
this.fn = fn
}
_next(value) {
const { isStopped } = this.innerSubscription || {
isStopped: true
}
if (!isStopped) {
this.buffer = [...this.buffer, value]
} else {
const o$ = this.fn(value)
this.innerSubscription = o$.subscribe({
next: value => {
this.destination.next(value)
},
complete: () => {
console.log(this.buffer)
if (this.buffer.length) {
const [first, ...rest] = this.buffer
this.buffer = rest
this._next(first)
}
}
})
// to tell when the outter subscription complete, the inner subscription should also completed
this.add(this.innerSubscription)
}
}
}
[RxJS] `add` Inner Subscriptions to Outer Subscribers to `unsubscribe` in RxJS的更多相关文章
- [RxJS] Add debug method to Observable in TypeScript
Observable.prototype.debug = function(message: any) { return this.do( (next) => { if(!environment ...
- RxJS速成 (下)
上一部分: http://www.cnblogs.com/cgzl/p/8641738.html Subject Subject比较特殊, 它即是Observable又是Observer. 作为Obs ...
- RxJS -- Subscription
Subscription是什么? 当subscribe一个observable的时候, 返回的就是一个subscription. 它是一个一次性对象(disposable), 它有一个非常重要的方法 ...
- rxjs 入门--环境配置
原文: https://codingthesmartway.com/getting-started-with-rxjs-part-1-setting-up-the-development-enviro ...
- rxjs与vue
原创文章,转载请注明出处 使用vue-rx插件将vue和rxjs联系起来 在main.js中将vue-rx注入vue中 import Vue from 'vue' import App from '. ...
- [译]RxJS 5.X基础篇
欢迎指错与讨论 : ) 当前RxJS版本:5.0.0-beta.10.更详细的内容尽在RxJS官网http://reactivex.io/rxjs/manual/overview.html.文章比较长 ...
- [RxJS + AngularJS] Sync Requests with RxJS and Angular
When you implement a search bar, the user can make several different queries in a row. With a Promis ...
- angular2 学习笔记 ( rxjs 流 )
RxJS 博大精深,看了好几篇文章都没有明白. 范围牵扯到了函数响应式开发去了... 我对函数式一知半解, 响应式更是第一次听到... 唉...不过日子还是得过...混着过先呗 我目前所理解的很浅, ...
- [Angular 2] Managing State in RxJS with StartWith and Scan
The scan operator in RxJS is the main key to managing values and states in your stream. Scan behaves ...
随机推荐
- 多表单异步验证 可以用 Promise validate
https://www.jb51.net/article/140062.htm vue动态绑定组件子父组件多表单验证功能的实现代码 // 加载组件:每次下拉框监听则给changValue新赋值,如果下 ...
- hard fault 学习记录
使用 segger 的 hard fault 的源文件后,当调试时,发生硬件错误的时候,可以查看 HardFaultRegs 中的内容,并对比 segger_HardFaultHandler.c 中的 ...
- vue与node和npm关系
(1)node功能 准确的说是使用vue-cli 脚手架搭建项目的时候需要nodejs.也可以用script标签引入vue.min.js这样的,在js里实例化vue也行. 使用node有几件事,打包部 ...
- SoapUI对于Json数据进行属性值获取与传递
SoapUI的Property Transfer功能可以很好地对接口请求返回的数据进行参数属性获取与传递,但对于Json数据,SoapUI会把数据格式先转换成XML格式,但实际情况却是,转换后的XML ...
- 小程序request请求 POST请求参数传递不到后台
wx.request({ url: 'https://xxx.com/xxxx.php', data: { 'jscode': code }, method: 'POST', header: { &q ...
- git 设置ss代理
git config --global https.proxy http://127.0.0.1:1080 git config --global https.proxy https:// ...
- 「 HDOJ P3887 」 Counting Offspring
翻译 题目描述 给你一棵树,和它的树根 $P$,并且节点从 $1\rightarrow n$ 编号,现在定义 $f(i)$ 为 $i$ 的子树中,节点编号小于 $i$ 的节点的个数. 输入格式 有多组 ...
- 如何使用MySQL一个表中的字段更新另一个表中字段
[本文出自:https://www.jb51.net/article/150323.htm] 这篇文章主要介绍了如何使用MySQL一个表中的字段更新另一个表中字段,需要的朋友可以参考下 1,修改1列 ...
- 从多表连接后的select count(*)看待SQL优化
从多表连接后的select count(*)看待SQL优化 一朋友问我,以下这SQL能直接改写成select count(*) from a吗? SELECT COUNT(*) FROM a LEFT ...
- Beego:原生方式使用MySQL
示例: package controllers import ( "database/sql" "fmt" "github.com/astaxie/b ...