【问题标题】:RxJS5 operator similiar to .combineLatest but fire whenever a single observable emitsRxJS 操作符与 .combineLatest 类似,但只要有单个 observable 发出就会触发
【发布时间】:2017-04-08 18:32:44
【问题描述】:

我正在寻找一种方法将多个 Observable 组合成一个标量值的平面元组 - 类似于 .combineLatest() - 但除了它应该发出一个新的值元组,即使其中一个没有发出任何值source observables - 在元组中为那些尚未发射的 observables 产生“未定义”。

例子:

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

【问题讨论】:

    标签: javascript typescript rxjs rxjs5 angular2-observables


    【解决方案1】:

    将两个主题 startWith 设为未定义值,因此当其中一个发出第一个值时,combineLatest 也会发出并将其与另一个主题的起始值组合。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-22
      • 2017-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-05
      • 2017-02-15
      相关资源
      最近更新 更多