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 innerSubscribe_1 = require("../innerSubscribe");
17 function debounce(durationSelector) {
18 return function (source) { return source.lift(new DebounceOperator(durationSelector)); };
20 exports.debounce = debounce;
21 var DebounceOperator = (function () {
22 function DebounceOperator(durationSelector) {
23 this.durationSelector = durationSelector;
25 DebounceOperator.prototype.call = function (subscriber, source) {
26 return source.subscribe(new DebounceSubscriber(subscriber, this.durationSelector));
28 return DebounceOperator;
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;
38 DebounceSubscriber.prototype._next = function (value) {
40 var result = this.durationSelector.call(this, value);
42 this._tryNext(value, result);
46 this.destination.error(err);
49 DebounceSubscriber.prototype._complete = function () {
51 this.destination.complete();
53 DebounceSubscriber.prototype._tryNext = function (value, duration) {
54 var subscription = this.durationSubscription;
58 subscription.unsubscribe();
59 this.remove(subscription);
61 subscription = innerSubscribe_1.innerSubscribe(duration, new innerSubscribe_1.SimpleInnerSubscriber(this));
62 if (subscription && !subscription.closed) {
63 this.add(this.durationSubscription = subscription);
66 DebounceSubscriber.prototype.notifyNext = function () {
69 DebounceSubscriber.prototype.notifyComplete = function () {
72 DebounceSubscriber.prototype.emitValue = function () {
74 var value = this.value;
75 var subscription = this.durationSubscription;
77 this.durationSubscription = undefined;
78 subscription.unsubscribe();
79 this.remove(subscription);
81 this.value = undefined;
82 this.hasValue = false;
83 _super.prototype._next.call(this, value);
86 return DebounceSubscriber;
87 }(innerSubscribe_1.SimpleOuterSubscriber));
88 //# sourceMappingURL=debounce.js.map