當(dāng)前位置:
首頁(yè) >
rxjs里withLatestFrom operators的用法
發(fā)布時(shí)間:2023/12/19
43
豆豆
生活随笔
收集整理的這篇文章主要介紹了
rxjs里withLatestFrom operators的用法
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Combines the source Observable with other Observables to create an Observable whose values are calculated from the latest values of each, only when the source emits.
上圖說(shuō)明:從時(shí)間軸上看,source
Observable emit value a時(shí),沒(méi)有其他輸入的Observable,因此value a被discard;emit b時(shí),其他Observable最新的值為1,因此最后output為b1;對(duì)c,d,e來(lái)說(shuō),另一個(gè)Observable最新的值為4,因此最后的值為c4,d4和e4.
看個(gè)例子:
const clicks = fromEvent(document, 'click'); const timer = interval(1000); const result = clicks.pipe(withLatestFrom(timer)); result.subscribe(x => console.log('diablo : ' + x));輸出:
如果我們把另一個(gè)Observable emit值也打印出來(lái),就能看得更清楚:
要獲取更多Jerry的原創(chuàng)文章,請(qǐng)關(guān)注公眾號(hào)"汪子熙":
總結(jié)
以上是生活随笔為你收集整理的rxjs里withLatestFrom operators的用法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 只狼商人黑笠在哪 只狼黑笠之狸位置一览
- 下一篇: rxjs里debounceTime op