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的更多相关文章

  1. [RxJS] Add debug method to Observable in TypeScript

    Observable.prototype.debug = function(message: any) { return this.do( (next) => { if(!environment ...

  2. RxJS速成 (下)

    上一部分: http://www.cnblogs.com/cgzl/p/8641738.html Subject Subject比较特殊, 它即是Observable又是Observer. 作为Obs ...

  3. RxJS -- Subscription

    Subscription是什么? 当subscribe一个observable的时候, 返回的就是一个subscription. 它是一个一次性对象(disposable), 它有一个非常重要的方法 ...

  4. rxjs 入门--环境配置

    原文: https://codingthesmartway.com/getting-started-with-rxjs-part-1-setting-up-the-development-enviro ...

  5. rxjs与vue

    原创文章,转载请注明出处 使用vue-rx插件将vue和rxjs联系起来 在main.js中将vue-rx注入vue中 import Vue from 'vue' import App from '. ...

  6. [译]RxJS 5.X基础篇

    欢迎指错与讨论 : ) 当前RxJS版本:5.0.0-beta.10.更详细的内容尽在RxJS官网http://reactivex.io/rxjs/manual/overview.html.文章比较长 ...

  7. [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 ...

  8. angular2 学习笔记 ( rxjs 流 )

    RxJS 博大精深,看了好几篇文章都没有明白. 范围牵扯到了函数响应式开发去了... 我对函数式一知半解, 响应式更是第一次听到... 唉...不过日子还是得过...混着过先呗 我目前所理解的很浅,  ...

  9. [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 ...

随机推荐

  1. Java会话(session)管理

    会话概述 什么是会话 简单的理解:用户打开浏览器,点击多个超链接,访问Web服务器上多个资源,然后关闭浏览器,整个过程称之为一次会话. 需要解决的问题 每个用户在使用浏览器与服务器会话的过程中,会产生 ...

  2. [LUOGU] P2187 小Z的笔记

    看范围猜方程,应该是O(n)级别的 f[i]表示前i个合法的最小代价,转移需要枚举断点位置,O(n^2) f[i]表示前i个合法留下的最大个数,同时更新距离最近的26个字母的位置,O(n)转移 f[i ...

  3. dotTrace激活服务器

    http://active.09l.me IntelliJ IDEA 7.0 或 更高DataGrip 1.0或更高ReSharper 3.1 或更高ReSharper Cpp 1.0 或更高dotT ...

  4. 转:使用 /proc 文件系统来访问 Linux 内核的内容

    使用 /proc 文件系统来访问 Linux 内核的内容 https://www.ibm.com/developerworks/cn/linux/l-proc.html /proc 文件系统并不是 G ...

  5. spring tool suite (sts) 创建springmvc(没有实践)

    摘自:STS(Spring Tool Suite)建立默认的spring mvc项目 老外的原创,网址:http://www.codejava.NET/frameworks/spring/spring ...

  6. 【练习】reserving.kr 之imageprc write up

    补充:c++ builder 与 windows  API经典范例 #include <vcl.h> #pragma hdrstop #include "Unit1.h" ...

  7. Laravel(4.2)-->whereHas/ whereDoesntHave

    在开发过程中,有时间需要用 wherehas 联合查询 出想要的结果,但是有的时候想搜索出不在关联表中出现的数据 whereDoesntHave(例:搜索出开卡的用户和没有开卡的用户)if($is_o ...

  8. fiddler终极教程

    http://www.cnblogs.com/yoyoketang/tag/fiddler/

  9. Android TransitionDrawable:过渡动画Drawable

    Android TransitionDrawable实现一种可以用动画表示的Drawable.写一个例子. package zhangphil.app; import android.graphics ...

  10. JS 回车跳转

    window.onload = function () { SeteasyuiTheme(); jQuery(':input:enabled').addClass('enterIndex'); var ...