簡體   English   中英

RxJS5運算符與.combineLatest類似,但只要發出單個可觀察對象就觸發

[英]RxJS5 operator similiar to .combineLatest but fire whenever a single observable emits

我正在尋找一種將多個Observable組合成標量值的平面元組的方法-與.combineLatest()類似-但有例外,即使在源可觀察項之一上未發出任何值,它也應該發出新的值元組-元組中的yieldung“未定義”,用於那些尚未發出的可觀察對象。

例:

const s1 = new Subject<string>();
const s2 = new Subject<string>();

Observable.combineWithUndefined(s1, s2).subscribe( ([t1, t2]) => {
    console.log(t1.toString() + " " + t2.toString());
});

s1.next("Hello");
s2.next("John");

// expected output:
// Hello undefined
// Hello John

使兩個主題開始時具有未定義的值,因此當其中一個主題發出第一個值時,combinateLatest也將發光,並將其與另一個主題的起始值合並。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM