0

Actually I need to implement something like debounce operator, but let's take an example. If I set debounce for 5 sec, so user can click on button 10 time within 5 sec and just after 5 sec expire the last click event will be taken to account.

What I need is option when 5 sec set as a time range and when user click 10 times just first click will be taken to account immediately and all other clicks that were emitted within 5 sec time range will be dismissed.

After 5 sec user can start clicking again.

How to do it?

Sirop4ik
  • 4,543
  • 2
  • 54
  • 121
  • Have a look at this https://stackoverflow.com/questions/57059666/how-does-throttletime-operators-config-parameter-work-throttleconfig – Goga Koreli Apr 19 '20 at 18:37

1 Answers1

2

There is another operator in RxJS to accomplish your task, throttleTime.

It will subscribe to the first value emitted and then wait for 5second and then again emit value after 5 second.

const source = fromEvent(document, 'click').pipe(
  throttleTime(5000),
);

Please find working example here: https://stackblitz.com/edit/rxjs-hwviuc

You can study more on throttleTime here

Jasdeep Singh
  • 7,901
  • 1
  • 11
  • 28