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 to the backend (which counts the votes). User can submit button multiple times, but I'd like to limit the times per second button can be pressed.
I know throttleTime
and debounceTime
operators can do that, but which one should I choose?
const upvoteClicks = fromEvent(this.el.nativeElement, 'click')
.pipe(debounceTime(500))
.subscribe(() => this.myService.postUpvote(this.postId));
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…