[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 ...
随机推荐
- ref版的 摄像头 读取 因为id的时候,id不能重复 还要用时间戳,比较麻烦
<!-- * @description 摄像头vue版实例 * @fileName cameraObject.vue * @author 彭成刚 * @date // :: * @version ...
- import downloadjs from 'downloadjs' 如果是自己写的函数 没用默认导出 记得加花括号 例如 import { download } from './data.js'
import downloadjs from 'downloadjs' 如果是自己写的函数 没用默认导出 记得加花括号 例如 import { download } from './data.js'
- 批处理 更新 svn git hg
@echo off Setlocal enabledelayedexpansion ::CODER BY Administrator POWERD BY iBAT 1.6 ::设置svn默认安装位置以 ...
- 文本三剑客之grep
接受正则表达式,按行匹配,将会过滤出匹配的所有行 格式: grep [OPTION]... PATTERN [FILE]... 可以看出,grep后可以同时接多个文件 选项OPTIO ...
- npm start问题
问题:在执行命令npm start 是出现下列问题: npm [] WARN invalid config loglevel="notice" [] npm WARN invali ...
- 数据结构实验7:实现二分查找、二叉排序(查找)树和AVL树
实验7 学号: 姓名: 专业: 7.1实验目的 (1) 掌握顺序表的查找方法,尤其是二分查找方法. (2) 掌握二叉排序树的建立及查找. 查找是软件设计中的最常用的运算,查找所涉及到 ...
- 如何在开发时用PC端对移动端页面进行调试
原文转载于:https://cnodejs.org/topic/56ebdf2db705742136388f71 项目名称: spy-debugger 项目地址:https://github.com/ ...
- Haproxy的安装与配置
一.Haproxy概念 Haproxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案.Haproxy特别适用于那些负载特大的web站点,这 ...
- 【07】QQ群管理公告小结:
[07]QQ群管理公告小结: 01,请看公告遵守相关规定. 02,群内除QQ自带的缺省表情外(不是QQ的VIP或大图表情),禁止发送大表情,大图片(展示问题的屏幕截图除外), 03,修改群名片 ...
- php5.5编译安装
系统环境:centos6.5PHP包:5.5.15https://wiki.swoole.com/wiki/page/177.html下载 PHP 源码包wget http://cn2.php.net ...