RxJS与last和emit进行比较

RxJS compare to last and emit

本文关键字:比较 emit last RxJS      更新时间:2023-09-26

我对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) => { })

检查文档