The lift method on each source hides away the internals of RxJS so you can simply connect a source to the subscriber you're working with. The lift method take an object with a call function with subscriber and source arguments, then it's up to you how you want to connect them together.

Previous we created a custom subscriber, we do it in subscribe() function:

import { from, Subscriber } from "rxjs";

const observable$ = from([1, 2, 3, 4, 5]);

const subscriber = {
next: value => {
console.log(value);
},
complete: () => {
console.log("done");
},
error: value => {
console.log(value);
}
}; class DoulbeSubscriber extends Subscriber {
_next(value) {
this.destination.next(value * 2);
}
} observable$.subscribe(new DoulbeSubscriber(subscriber));

Of course it isn't ideal to do the transformation in subscriber.

Better way is that we can do though `pipe`, create a custom subscriber and using in the pipe:

const doulbe = source => {
return source.lift({
call(sub, source) {
source.subscribe(new DoulbeSubscriber(sub));
}
});
}; observable$.pipe(doulbe).subscribe(subscriber);

We can use `lift` function which accpet an object has a call(subscriber, source).

[RxJS] Use `lift` to Connect a `source` to a `subscriber` in RxJS的更多相关文章

  1. SWD Connect/Transfer Source Code

    Serial Wire Debug interface The Serial Wire Debug protocol operates with a synchronous serial interf ...

  2. angularjs 运行时报错ERROR in node_modules/rxjs/internal/types.d.ts(81,44): error TS1005: ';' expected. node_modules/rxjs/internal/types.d.ts(81,74): error TS1005: ';' expected. node_modules/rxjs/internal/t

    解决方法: 在package.json文件里面 修改 "rxjs": "^6.0.0" 为 "rxjs": "6.0.0" ...

  3. [RxJS] Create a Reusable Operator from Scratch in RxJS

    With knowledge of extending Subscriber and using source.lift to connect a source to a subscriber, yo ...

  4. rxjs的世界

    rxjs学习了几个月了,看了大量的东西,在理解Observable的本文借鉴的是渔夫的故事,原文,知识的主线以<深入浅出rxjs>为主,动图借鉴了rxjs中文社区翻译的文章和国外的一个动图 ...

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

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

  6. angular2 学习笔记 ( rxjs 流 )

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

  7. rxjs简单入门

    rxjs全名Reactive Extensions for JavaScript,Javascript的响应式扩展, 响应式的思路是把随时间不断变化的数据.状态.事件等等转成可被观察的序列(Obser ...

  8. RxJS v6 学习指南

    为什么要使用 RxJS RxJS 是一套处理异步编程的 API,那么我将从异步讲起. 前端编程中的异步有:事件(event).AJAX.动画(animation).定时器(timer). 异步常见的问 ...

  9. RxJS库

    介绍 RxJS是一个异步编程的库,同时它通过observable序列来实现基于事件的编程.它提供了一个核心的类型:Observable,几个辅助类型(Observer,Schedulers,Subje ...

随机推荐

  1. clone对象或数组

    function clone(obj) { var o; if (typeof obj == "object") { if (obj === null) { o = null; } ...

  2. zabbix监控流程图

  3. Eclipse的PyDev插件安装及解决安装后找不到的问题

    一.环境 windows 7 64bit eclipse 4.5.2 pydev jdk7u55 二.安装步骤 1. 安装JDK eclipse依赖于Java环境,所以需要安装Java运行环境JRE. ...

  4. saltstack快速部署

    yum install wget deltarpm -y wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/rep ...

  5. JSP默认选中下拉框的某一项

    注意<c:if>标签要写在<option>标签里面 <select id="salesInventory_${s.index}" style=&quo ...

  6. 利用OpenXml读取、导出Excel

    OpenXml是通过 XML 文档提供行集视图.由于OPENXML 是行集提供程序,因此可在会出现行集提供程序(如表.视图或 OPENROWSET 函数)的 Transact-SQL 语句中使用 OP ...

  7. python操作剪贴板错误提示:pywintypes.error: (1418, 'GetClipboardData',线程没有打开的剪贴板)

    问题现象:通过打断点,一步步调试可以正常复制和粘贴剪贴板数据.但是直接运行会报错pywintypes.error: (1418, 'GetClipboardData',线程没有打开的剪贴板) 问题原因 ...

  8. Fiddler抓包-get与post请求

    from:https://www.cnblogs.com/yoyoketang/p/6719717.html 本篇以博客园的请求为例,简单分析get与post数据有何不一样,以后也能分辨出哪些是get ...

  9. Leetcode 221.最大的正方形

    最大的正方形 在一个由 0 和 1 组成的二维矩阵内,找到只包含 1 的最大正方形,并返回其面积. 示例: 输入: 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0 输出 ...

  10. PTA 01-复杂度2 Maximum Subsequence Sum (25分)

    题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/663 5-1 Maximum Subsequence Sum   (25分) Given ...