【发布时间】:2021-05-03 09:17:18
【问题描述】:
在 RxJS 中,当您需要组合两个 Observables 并且仅在其中一个发出时发出,您使用 withLatestFrom
source$.pipe(
withLatestFrom(other$),
map(([sourceValue, otherValue]) => ...) // this is only executed when `source$` has new values, regardless of `other$` emission
)
如果source$ 发出多次但other$ 没有发出,您总是得到相同的最新值并执行 执行map。
如果不需要“signalling”流的值,可以使用sample。
interestingStream$.pipe(
sample(signallingStream$),
map((interestingValue) => ...) // this function does not receive `signallingStream$`'s values
)
但是,map 仅在 signallingStream$ 发出 interestingStream$ 发出新值后才会执行;没有值向下游发出两次。
所以我的问题是,是否有一个运算符、运算符的组合或其他东西可以让我多次获得源流的最新值,而不会强迫我获取和忽略信号流的值,例如下面的sn-p?
signallingStream$.pipe(
withLatestFrom(interestingStream$),
map(([_ignore_, interestingValue]) => interestingValue),
)
【问题讨论】:
标签: typescript rxjs stream observable reactivex