[RxJS] Use `lift` to Connect a `source` to a `subscriber` in RxJS
to in use connect source Rxjs
2023-09-14 09:00:49 时间
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).
相关文章
- ORA-01239: database must be in ARCHIVELOG mode to use external cache ORACLE 报错 故障修复 远程处理
- ORA-01650: unable to extend rollback segment string by string in tablespace string ORACLE 报错 故障修复 远程处理
- ORA-26901: string propagation sender in the combined capture and apply mode is to be suspended while apply is disabled. ORACLE 报错 故障修复 远程处理
- ORA-27086: unable to lock file – already in use ORACLE 报错 故障修复 远程处理
- ORA-29518: name string resolved to an object in schema string that is not a Java class ORACLE 报错 故障修复 远程处理
- ORA-31069: Cannot apply typed changes to non-schema-based XMLType nodes ORACLE 报错 故障修复 远程处理
- ORA-31198: Mismatch in number of bytes transferred due to non-binary mode ORACLE 报错 故障修复 远程处理
- ORA-39138: Insufficient privileges to load data not in your schema ORACLE 报错 故障修复 远程处理
- ORA-39915: Partition string of table string.string in tablespace string points to LOB segment string.string in tablespace string. ORACLE 报错 故障修复 远程处理
- ORA-48170: unable to lock file – already in use ORACLE 报错 故障修复 远程处理
- ORA-01239: database must be in ARCHIVELOG mode to use external cache ORACLE 报错 故障修复 远程处理
- MySQL Error number: MY-011422; Symbol: ER_KEYRING_AWS_FAILED_TO_ACCESS_OR_CREATE_KEYRING_DIR; SQLSTATE: HY000 报错 故障修复 远程处理
- ORA-06443: ssvpstev: Incorrect parameter passed to function call ORACLE 报错 故障修复 远程处理
- ORA-09789: sllfsk: unable to read file. ORACLE 报错 故障修复 远程处理
- ORA-13212: failed to compare tile with the window object ORACLE 报错 故障修复 远程处理
- ORA-13283: failure to get new geometry object for conversion in place ORACLE 报错 故障修复 远程处理
- ORA-16777: unable to find the destination entry of a standby database in V$ARCHIVE_DEST ORACLE 报错 故障修复 远程处理
- 查询利用Oracle In查询实现列值范围筛选(oracle列值in)
- Linux SVN User: A Guide to Version Control in a Linux Environment(linuxsvn用户)
- 语句SQL Server中使用IN语句处理多值查询(sqlserver中in)
- 深入剖析MySQL中IN和等于操作的差异与应用(mysql中in和等于)
- MySQL中IN操作不去重,如何解决重复数据问题(mysql中in 不去重)
- 符号Oracle 中与 IN 的区别(Oracle中=和in)