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 exports.defaultThrottleConfig = {
21 function throttle(durationSelector, config) {
22 if (config === void 0) { config = exports.defaultThrottleConfig; }
23 return function (source) { return source.lift(new ThrottleOperator(durationSelector, !!config.leading, !!config.trailing)); };
25 exports.throttle = throttle;
26 var ThrottleOperator = (function () {
27 function ThrottleOperator(durationSelector, leading, trailing) {
28 this.durationSelector = durationSelector;
29 this.leading = leading;
30 this.trailing = trailing;
32 ThrottleOperator.prototype.call = function (subscriber, source) {
33 return source.subscribe(new ThrottleSubscriber(subscriber, this.durationSelector, this.leading, this.trailing));
35 return ThrottleOperator;
37 var ThrottleSubscriber = (function (_super) {
38 __extends(ThrottleSubscriber, _super);
39 function ThrottleSubscriber(destination, durationSelector, _leading, _trailing) {
40 var _this = _super.call(this, destination) || this;
41 _this.destination = destination;
42 _this.durationSelector = durationSelector;
43 _this._leading = _leading;
44 _this._trailing = _trailing;
45 _this._hasValue = false;
48 ThrottleSubscriber.prototype._next = function (value) {
49 this._hasValue = true;
50 this._sendValue = value;
51 if (!this._throttled) {
60 ThrottleSubscriber.prototype.send = function () {
61 var _a = this, _hasValue = _a._hasValue, _sendValue = _a._sendValue;
63 this.destination.next(_sendValue);
64 this.throttle(_sendValue);
66 this._hasValue = false;
67 this._sendValue = undefined;
69 ThrottleSubscriber.prototype.throttle = function (value) {
70 var duration = this.tryDurationSelector(value);
72 this.add(this._throttled = innerSubscribe_1.innerSubscribe(duration, new innerSubscribe_1.SimpleInnerSubscriber(this)));
75 ThrottleSubscriber.prototype.tryDurationSelector = function (value) {
77 return this.durationSelector(value);
80 this.destination.error(err);
84 ThrottleSubscriber.prototype.throttlingDone = function () {
85 var _a = this, _throttled = _a._throttled, _trailing = _a._trailing;
87 _throttled.unsubscribe();
89 this._throttled = undefined;
94 ThrottleSubscriber.prototype.notifyNext = function () {
95 this.throttlingDone();
97 ThrottleSubscriber.prototype.notifyComplete = function () {
98 this.throttlingDone();
100 return ThrottleSubscriber;
101 }(innerSubscribe_1.SimpleOuterSubscriber));
102 //# sourceMappingURL=throttle.js.map