Learn RxJS
Search…
debounceTime

signature: debounceTime(dueTime: number, scheduler: Scheduler): Observable

Discard emitted values that take less than the specified time between output

💡 This operator is popular in scenarios such as type-ahead where the rate of user input must be controlled!

Examples

Example 1: Debouncing based on time between input
1
// RxJS v6+
2
import { fromEvent } from 'rxjs';
3
import { debounceTime, map } from 'rxjs/operators';
4
5
// elem ref
6
const searchBox = document.getElementById('search');
7
8
// streams
9
const keyup$ = fromEvent(searchBox, 'keyup');
10
11
// wait .5s between keyups to emit current value
12
keyup$
13
.pipe(
14
map((i: any) => i.currentTarget.value),
15
debounceTime(500)
16
)
17
.subscribe(console.log);
Copied!

Additional Resources

Last modified 1yr ago