简体   繁体   English

RxJS5运算符与.combineLatest类似,但只要发出单个可观察对象就触发

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

I am looking for a way to combine multiple Observables into a flat tuple of scalar values - similar to .combineLatest() - but with the exception that it should emit a new value tuple even when no value has been emitted on one of the source observables - yieldung "undefined" in the tuple for those observables that did not yet emit. 我正在寻找一种将多个Observable组合成标量值的平面元组的方法-与.combineLatest()类似-但有例外,即使在源可观察项之一上未发出任何值,它也应该发出新的值元组-元组中的yieldung“未定义”,用于那些尚未发出的可观察对象。

Example: 例:

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