Skip to content

Commit 8991b21

Browse files
committed
added throttle
1 parent b8c60e1 commit 8991b21

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

README.md

+25-1
Original file line numberDiff line numberDiff line change
@@ -2758,10 +2758,34 @@ export class App implements OnInit {
27582758
bootstrapApplication(App);
27592759
```
27602760

2761-
**throttle** -
2761+
**throttle** - Emits a value from the source Observable, then ignores subsequent source values for a duration determined by another Observable, then repeats this process.
27622762

27632763
```typescript
2764+
import 'zone.js/dist/zone';
2765+
import { Component, OnInit } from '@angular/core';
2766+
import { CommonModule } from '@angular/common';
2767+
import { bootstrapApplication } from '@angular/platform-browser';
2768+
import { fromEvent, throttle, interval } from 'rxjs';
27642769

2770+
@Component({
2771+
selector: 'my-app',
2772+
standalone: true,
2773+
imports: [CommonModule],
2774+
template: `
2775+
<h1>throttle Example</h1>
2776+
`,
2777+
})
2778+
export class App implements OnInit {
2779+
2780+
ngOnInit() {
2781+
const clicks = fromEvent(document, 'click');
2782+
const result = clicks.pipe(throttle(() => interval(1000)));
2783+
2784+
result.subscribe(x => console.log(x));
2785+
}
2786+
}
2787+
2788+
bootstrapApplication(App);
27652789
```
27662790

27672791
**throttleTime** -

0 commit comments

Comments
 (0)