💡 This operator is popular in scenarios such as type-ahead where the rate of user input must be controlled!
( StackBlitz )
// RxJS v6+
import { fromEvent } from 'rxjs';
import { debounceTime, map } from 'rxjs/operators';
// elem ref
const searchBox = document.getElementById('search');
// streams
const keyup$ = fromEvent(searchBox, 'keyup');
// wait .5s between keyups to emit current value
keyup$
.pipe(
map((i: any) => i.currentTarget.value),
debounceTime(500)
)
.subscribe(console.log);
- debounceTime 📰 - Official docs
- debounceTime - In Depth Dev Reference
- Transformation operator: debounce and debounceTime 🎥 💵 - André Staltz
- Time based operators comparison
- Build your own debounceTime operator 🎥 - Kwinten Pisman
📁 Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/debounceTime.ts