RxJS distinctUntilChanged - object comparsion

后端 未结 7 789
青春惊慌失措
青春惊慌失措 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:46

    When you have lodash in your application anyway, you can simply utilize lodash's isEqual() function, which does a deep comparison and perfectly matches the signature of distinctUntilChanged():

    .distinctUntilChanged(isEqual),
    

    Or if you have _ available (which is not recommended anymore these days):

    .distinctUntilChanged(_.isEqual),
    

提交回复
热议问题