1 import { Subscriber } from '../Subscriber';
2 import { async } from '../scheduler/async';
3 export function debounceTime(dueTime, scheduler = async) {
4 return (source) => source.lift(new DebounceTimeOperator(dueTime, scheduler));
6 class DebounceTimeOperator {
7 constructor(dueTime, scheduler) {
8 this.dueTime = dueTime;
9 this.scheduler = scheduler;
11 call(subscriber, source) {
12 return source.subscribe(new DebounceTimeSubscriber(subscriber, this.dueTime, this.scheduler));
15 class DebounceTimeSubscriber extends Subscriber {
16 constructor(destination, dueTime, scheduler) {
18 this.dueTime = dueTime;
19 this.scheduler = scheduler;
20 this.debouncedSubscription = null;
21 this.lastValue = null;
22 this.hasValue = false;
26 this.lastValue = value;
28 this.add(this.debouncedSubscription = this.scheduler.schedule(dispatchNext, this.dueTime, this));
32 this.destination.complete();
37 const { lastValue } = this;
38 this.lastValue = null;
39 this.hasValue = false;
40 this.destination.next(lastValue);
44 const debouncedSubscription = this.debouncedSubscription;
45 if (debouncedSubscription !== null) {
46 this.remove(debouncedSubscription);
47 debouncedSubscription.unsubscribe();
48 this.debouncedSubscription = null;
52 function dispatchNext(subscriber) {
53 subscriber.debouncedNext();
55 //# sourceMappingURL=debounceTime.js.map