【发布时间】:2019-10-20 23:03:51
【问题描述】:
我正在尝试了解 throttleTime 与 debounceTime 以及何时使用哪个?
我有一个投票按钮,可以向后端(计算投票数)发出 API 请求。用户可以多次提交按钮,但我想限制每秒可以按下按钮的次数。
我知道throttleTime 和debounceTime 运营商可以做到这一点,但我应该选择哪一个?
const upvoteClicks = fromEvent(this.el.nativeElement, 'click')
.pipe(debounceTime(500))
.subscribe(() => this.myService.postUpvote(this.postId));
【问题讨论】:
标签: rxjs observable rxjs-pipeable-operators