source: trip-planner-front/node_modules/rxjs/_esm2015/internal/operators/debounceTime.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.8 KB
Line 
1import { Subscriber } from '../Subscriber';
2import { async } from '../scheduler/async';
3export function debounceTime(dueTime, scheduler = async) {
4 return (source) => source.lift(new DebounceTimeOperator(dueTime, scheduler));
5}
6class DebounceTimeOperator {
7 constructor(dueTime, scheduler) {
8 this.dueTime = dueTime;
9 this.scheduler = scheduler;
10 }
11 call(subscriber, source) {
12 return source.subscribe(new DebounceTimeSubscriber(subscriber, this.dueTime, this.scheduler));
13 }
14}
15class DebounceTimeSubscriber extends Subscriber {
16 constructor(destination, dueTime, scheduler) {
17 super(destination);
18 this.dueTime = dueTime;
19 this.scheduler = scheduler;
20 this.debouncedSubscription = null;
21 this.lastValue = null;
22 this.hasValue = false;
23 }
24 _next(value) {
25 this.clearDebounce();
26 this.lastValue = value;
27 this.hasValue = true;
28 this.add(this.debouncedSubscription = this.scheduler.schedule(dispatchNext, this.dueTime, this));
29 }
30 _complete() {
31 this.debouncedNext();
32 this.destination.complete();
33 }
34 debouncedNext() {
35 this.clearDebounce();
36 if (this.hasValue) {
37 const { lastValue } = this;
38 this.lastValue = null;
39 this.hasValue = false;
40 this.destination.next(lastValue);
41 }
42 }
43 clearDebounce() {
44 const debouncedSubscription = this.debouncedSubscription;
45 if (debouncedSubscription !== null) {
46 this.remove(debouncedSubscription);
47 debouncedSubscription.unsubscribe();
48 this.debouncedSubscription = null;
49 }
50 }
51}
52function dispatchNext(subscriber) {
53 subscriber.debouncedNext();
54}
55//# sourceMappingURL=debounceTime.js.map
Note: See TracBrowser for help on using the repository browser.