RxJS distinctUntilChanged - object comparsion

后端 未结 7 785
青春惊慌失措
青春惊慌失措 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),
    
    0 讨论(0)
提交回复
热议问题