For example, if I have a button that I want to click twice in a second and count only once, it’s easy to do in Angular RXJS:

The source code:

  ngOnInit(): void {
    const button = document.querySelector('button');
    fromEvent(button, 'click').pipe(throttleTime(1000), scan(count= > count + 1.0))
    .subscribe(count= > console.log(`Clicked ${count} times`));
  }
Copy the code

Note the output timestamp: it does limit the flow:

For more of Jerry’s original articles, please follow the public account “Wang Zixi “: