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);
9 return function (d, b) {
11 function __() { this.constructor = d; }
12 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15 Object.defineProperty(exports, "__esModule", { value: true });
16 var OuterSubscriber_1 = require("../OuterSubscriber");
17 var subscribeToResult_1 = require("../util/subscribeToResult");
18 function debounce(durationSelector) {
19 return function (source) { return source.lift(new DebounceOperator(durationSelector)); };
21 exports.debounce = debounce;
22 var DebounceOperator = (function () {
23 function DebounceOperator(durationSelector) {
24 this.durationSelector = durationSelector;
26 DebounceOperator.prototype.call = function (subscriber, source) {
27 return source.subscribe(new DebounceSubscriber(subscriber, this.durationSelector));
29 return DebounceOperator;
31 var DebounceSubscriber = (function (_super) {
32 __extends(DebounceSubscriber, _super);
33 function DebounceSubscriber(destination, durationSelector) {
34 var _this = _super.call(this, destination) || this;
35 _this.durationSelector = durationSelector;
36 _this.hasValue = false;
37 _this.durationSubscription = null;
40 DebounceSubscriber.prototype._next = function (value) {
42 var result = this.durationSelector.call(this, value);
44 this._tryNext(value, result);
48 this.destination.error(err);
51 DebounceSubscriber.prototype._complete = function () {
53 this.destination.complete();
55 DebounceSubscriber.prototype._tryNext = function (value, duration) {
56 var subscription = this.durationSubscription;
60 subscription.unsubscribe();
61 this.remove(subscription);
63 subscription = subscribeToResult_1.subscribeToResult(this, duration);
64 if (subscription && !subscription.closed) {
65 this.add(this.durationSubscription = subscription);
68 DebounceSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
71 DebounceSubscriber.prototype.notifyComplete = function () {
74 DebounceSubscriber.prototype.emitValue = function () {
76 var value = this.value;
77 var subscription = this.durationSubscription;
79 this.durationSubscription = null;
80 subscription.unsubscribe();
81 this.remove(subscription);
84 this.hasValue = false;
85 _super.prototype._next.call(this, value);
88 return DebounceSubscriber;
89 }(OuterSubscriber_1.OuterSubscriber));
90 //# sourceMappingURL=debounce.js.map