Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / rxjs / internal / operators / debounce.js
1 "use strict";
2 var __extends = (this && this.__extends) || (function () {
3     var extendStatics = function (d, b) {
4         extendStatics = Object.setPrototypeOf ||
5             ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6             function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7         return extendStatics(d, b);
8     }
9     return function (d, b) {
10         extendStatics(d, b);
11         function __() { this.constructor = d; }
12         d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13     };
14 })();
15 Object.defineProperty(exports, "__esModule", { value: true });
16 var innerSubscribe_1 = require("../innerSubscribe");
17 function debounce(durationSelector) {
18     return function (source) { return source.lift(new DebounceOperator(durationSelector)); };
19 }
20 exports.debounce = debounce;
21 var DebounceOperator = (function () {
22     function DebounceOperator(durationSelector) {
23         this.durationSelector = durationSelector;
24     }
25     DebounceOperator.prototype.call = function (subscriber, source) {
26         return source.subscribe(new DebounceSubscriber(subscriber, this.durationSelector));
27     };
28     return DebounceOperator;
29 }());
30 var DebounceSubscriber = (function (_super) {
31     __extends(DebounceSubscriber, _super);
32     function DebounceSubscriber(destination, durationSelector) {
33         var _this = _super.call(this, destination) || this;
34         _this.durationSelector = durationSelector;
35         _this.hasValue = false;
36         return _this;
37     }
38     DebounceSubscriber.prototype._next = function (value) {
39         try {
40             var result = this.durationSelector.call(this, value);
41             if (result) {
42                 this._tryNext(value, result);
43             }
44         }
45         catch (err) {
46             this.destination.error(err);
47         }
48     };
49     DebounceSubscriber.prototype._complete = function () {
50         this.emitValue();
51         this.destination.complete();
52     };
53     DebounceSubscriber.prototype._tryNext = function (value, duration) {
54         var subscription = this.durationSubscription;
55         this.value = value;
56         this.hasValue = true;
57         if (subscription) {
58             subscription.unsubscribe();
59             this.remove(subscription);
60         }
61         subscription = innerSubscribe_1.innerSubscribe(duration, new innerSubscribe_1.SimpleInnerSubscriber(this));
62         if (subscription && !subscription.closed) {
63             this.add(this.durationSubscription = subscription);
64         }
65     };
66     DebounceSubscriber.prototype.notifyNext = function () {
67         this.emitValue();
68     };
69     DebounceSubscriber.prototype.notifyComplete = function () {
70         this.emitValue();
71     };
72     DebounceSubscriber.prototype.emitValue = function () {
73         if (this.hasValue) {
74             var value = this.value;
75             var subscription = this.durationSubscription;
76             if (subscription) {
77                 this.durationSubscription = undefined;
78                 subscription.unsubscribe();
79                 this.remove(subscription);
80             }
81             this.value = undefined;
82             this.hasValue = false;
83             _super.prototype._next.call(this, value);
84         }
85     };
86     return DebounceSubscriber;
87 }(innerSubscribe_1.SimpleOuterSubscriber));
88 //# sourceMappingURL=debounce.js.map