[RxJS] Use `lift` to Connect a `source` to a `subscriber` in RxJS
to in use connect source Rxjs
2023-09-14 08:59:17 时间
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).
相关文章
- MySQL启动报错[ERROR] Fatal error: Please read “Security“ section of the....to run mysqld as root!
- neo4j访问浏览器时报错:ServiceUnavailable: WebSocket connection failure. Due to security constraints in your
- use SceneKit to display 3d objects in an iOS project
- 'django.contrib.auth.middleware.AuthenticationMiddleware' must be in MIDDLEWARE in order to use the
- ORA-00850: PGA_AGGREGATE_TARGET string cannot be set to more than MEMORY_MAX_TARGET string. ORACLE 报错 故障修复 远程处理
- ORA-01194: file string needs more recovery to be consistent ORACLE 报错 故障修复 远程处理
- ORA-22295: cannot bind more than 4000 bytes data to LOB and LONG columns in 1 statement ORACLE 报错 故障修复 远程处理
- ORA-23420: interval must evaluate to a time in the future ORACLE 报错 故障修复 远程处理
- ORA-24355: attempt to store a negative number in an Unsigned Display type. ORACLE 报错 故障修复 远程处理
- ORA-27624: Smart I/O failed because the number of reconnects to the cell “string” exceeded the maximum allowed “string”. ORACLE 报错 故障修复 远程处理
- ORA-48157: null input to ADR initialization ORACLE 报错 故障修复 远程处理
- ORA-01239: database must be in ARCHIVELOG mode to use external cache ORACLE 报错 故障修复 远程处理
- ORA-01329: unable to truncate required build table ORACLE 报错 故障修复 远程处理
- ORA-01484: arrays can only be bound to PL/SQL statements ORACLE 报错 故障修复 远程处理
- MySQL Error number: MY-011405; Symbol: ER_KEYRING_ENCRYPTED_FILE_FAILED_TO_RESTORE_KEYRING; SQLSTATE: HY000 报错 故障修复 远程处理
- MySQL Error number: MY-011610; Symbol: ER_GRP_RPL_APPENDING_DATA_TO_INTERNAL_CACHE_FAILED; SQLSTATE: HY000 报错 故障修复 远程处理
- ORA-09754: sppst: invalid process number passed to sppst. ORACLE 报错 故障修复 远程处理
- ORA-15156: cluster in rolling upgrade from version [string] to [string] ORACLE 报错 故障修复 远程处理
- ORA-16771: failover to a physical standby database failed ORACLE 报错 故障修复 远程处理
- DataFrame.to_dict(orient=’dict’)详解编程语言
- Mastering Looping in Linux: A Comprehensive Guide to For Loops(linuxfor循环)
- Exploring the Power of Linux with Hydra: A Comprehensive Guide to Network Security(linuxhydra)
- 如何有效运用SQL Server的IN语句(sqlserver用in)
- 借助MSSQL语句实现IN的强大功能(mssql语句 in)
- MySQL中的IN关键字有什么含义(mysql中in什么意思)
- Oracle中两个IN叠加的查询技巧(oracle两个in叠加)
- 华为5G To B的“思维导图”