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. 浅谈nodejs与npm

    (1)npm介绍 在正式介绍Node.js学习之前,我们先认识一下npm. npm是什么东西?npm其实是Node.js的包管理工具(package manager). 为啥需要一个包管理工具呢?因为 ...

  2. 背包DP || Codeforces 544C Writing Code

    程序员写bug的故事23333 题意:n个程序员,一共写m行程序,最多产生b个bug,问方案数 思路:f[i][j]表示写了i行,产生了j个bug的方案数,因为每个人都是可以独立的,所以i循环到n都做 ...

  3. Microsoft Windows Server DHCP

    Microsoft Windows Server DHCP DHCP IP地址第一个来源是DHCP服务器,第二个来源是PPP点对点协议(ADSL为PPPOE);DHCP是Dynamic Host Co ...

  4. Centos 7 编译php 7.2.10

    步骤一:安装依赖 yum install -y wget gcc gcc-c++ gd-devel zlib-devel libjpeg-devel libpng-devel libiconv-dev ...

  5. luogu1502 窗口的星星

    扫描线应该打懒标记的-- #include <algorithm> #include <iostream> #include <cstdio> using name ...

  6. Python模块学习 - openpyxl读写excel

    openpyxl模块介绍 openpyxl模块是一个读写Excel 2010文档的Python库,如果要处理更早格式的Excel文档,需要用到额外的库,openpyxl是一个比较综合的工具,能够同时读 ...

  7. 大数据学习——hive基本操作

    1 建表 create table student(id int,name string ,age int) row format delimitedfields terminated by ','; ...

  8. NYOJ 237 游戏高手的烦恼

    游戏高手的烦恼时间限制:1000 ms | 内存限制:65535 KB难度:5描述有一位传说级游戏高手,在闲暇时间里玩起了一个小游戏,游戏中,一个n*n的方块形区域里有许多敌人,玩家可以使用炸弹炸掉某 ...

  9. POJ-Crazy tea party,很好的一道数学题~~~

    Crazy tea party Time Limit: 1000MS   Memory Limit: 10000K        Description n participants of <& ...

  10. [codeforces538F]A Heap of Heaps

    [codeforces538F]A Heap of Heaps 试题描述 Andrew skipped lessons on the subject 'Algorithms and Data Stru ...