RxJS 与上次比较并发出

RxJS compare to last and emit

我是 ReactiveJS 的新手,我想实现以下目标:

仅在具有与上一个时间戳不同的时间戳 (updated_at) 时才发出值(对象)。

var checkJobsRx = new Rx.Subject();
checkJobsRx
.dosomethinghere()
.subscribe(function (data) {})

请阅读有关 distinctUntilChanged() 的文档。 http://reactivex.io/documentation/operators/distinct.html

我想下面的代码就是问题的答案。(只添加了 1 行)

var checkJobsRx = new Rx.Subject();
  checkJobsRx
 .dosomethinghere()
 .distinctUntilChanged(function(job) { return job.updated_at })
 .subscribe(function (data) {})

您可以使用 distinctUntilChanged 检查发出的重复值:

checkJobsRx
  .map(fooBar)
  .distinctUntilChanged((item) => item.updated_at)
  .subscribe((data) => { })

勾选the documentation