如果三个对象键之一已更改,则我想触发.subscribe()

如果我复制并粘贴每个键的方法,它将起作用:

this.myService.loadData(this.dataContainer.id, true)
      .distinctUntilChanged((updatedData) => { return updatedData.relations; })
      .subscribe(updatedData => {
        console.log("relations changed",updatedData);
    });

this.myService.loadData(this.dataContainer.id, true)
      .distinctUntilChanged((updatedData) => { return updatedData.parent; })
      .subscribe(updatedData => {
        console.log("parent changed",updatedData);
    });

this.myService.loadData(this.dataContainer.id, true)
      .distinctUntilChanged((updatedData) => { return updatedData.children; })
      .subscribe(updatedData => {
        console.log("children changed",updatedData);
    });


如果将distinctUntilChanged比较器设置为返回整个updatedData对象,则我的订阅永远不会触发。

如何将三个dinstinctUntilChanged组合为一个减速器?

最佳答案

单程:

const data$ = this.myService.loadData(this.dataContainer.id, true);

Observable
  .combineLatest(
    $data.distinctUntilChanged(data => updatedData.relations),
    $data.distinctUntilChanged(data => updatedData.parent),
    $data.distinctUntilChanged(data => updatedData.children),
    data => data
  )
  .subscribe(updatedData => {
    console.log("relation|parent|children changed", updatedData);
  });

07-24 09:17