What is the difference between throttleTime vs debounceTime in RxJS and when to choose which?

后端 未结 1 1346
没有蜡笔的小新
没有蜡笔的小新 2021-01-01 18:58

I\'m trying to understand throttleTime vs debounceTime and which one is to be used when?

I have an upvote button that makes an API request t

相关标签:
1条回答
  • 2021-01-01 19:26

    I think in your case throttleTime works a little bit better, because you want to make the api request as soon as user clicks the button.

    Both throttleTime and debounceTime ignore the events which come in the meantime, but throttleTime emits right away, while debounceTime waits for additional delay.

    You can visually see that very well at https://rxmarbles.com

    What is more, throttleTime vs debounceTime in RxJS article provides a good overview of both operators.

    0 讨论(0)
提交回复
热议问题