RxJS combineLatestWith
所有输入至少发出一次后,任意一方更新都会组合双方最新值。
source$.pipe(combineLatestWith(other$))时间线如何变化
- 1first$ 先发出 Ada
last$ 还没有值,因此暂不输出。
- 2双方都有首值
组合为 Ada Lovelace。
- 3first$ 更新
使用 last$ 的最新值组合 Grace Lovelace。
- 4last$ 更新
任意一方更新都会产生新的组合。
受支持的示例代码
实验室只根据下列示例中的关键操作符生成预设时间线,不执行任意输入代码。
import { combineLatestWith, map } from 'rxjs'
const fullName$ = firstName$.pipe(
combineLatestWith(lastName$),
map(([first, last]) => `${first} ${last}`)
)
fullName$.subscribe(console.log)