How to use RxJs distinctUntilChanged?

懵懂的女人 提交于 2019-12-04 22:36:55

I got an answer here. Basically the function signature changed from (key selector, comparator) to (comparator, key selector).

This is how the example is done in v5:

Observable.of(['a', 1], ['a', 1], ['a', 0], ['a', 1])
  .distinctUntilChanged(null, x => x[1])
  .subscribe(x => console.log(x))

Here is a sample with your code is Rxjs V4. You will see that it works correctly.

Observable.of(['a', 1], ['a', 1], ['a', 0], ['a', 1])
  .distinctUntilChanged(x => x[1])
  .subscribe(x => console.log(x))
...

So it seems to be something with the new beta version. Here are the specs for distinctUntilChanged. The operator itself seems to be working as in version 4.

To test things out, I recommend you trace the output of each function by inserting a .do(function(x){console.log(x)}) in between operators. I can only think of the of operator maybe passing on only the last element of the array.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!