RxJS distinctUntilChanged - object comparsion

后端 未结 7 788
青春惊慌失措
青春惊慌失措 2021-01-03 20:57

I have stream of objects and I need to compare if current object is not same as previous and in this case emit new value. I found distinctUntilChanged operator should do exa

7条回答
  •  心在旅途
    2021-01-03 21:28

    I had the same problem, and fixed it with using JSON.stringify to compare the objects:

    .distinctUntilChanged((a, b) => JSON.stringify(a) === JSON.stringify(b))

    Dirty but working code.

提交回复
热议问题