1 /** PURE_IMPORTS_START tslib,_OuterSubscriber,_util_subscribeToResult PURE_IMPORTS_END */
2 import * as tslib_1 from "tslib";
3 import { OuterSubscriber } from '../OuterSubscriber';
4 import { subscribeToResult } from '../util/subscribeToResult';
5 export var defaultThrottleConfig = {
9 export function throttle(durationSelector, config) {
10 if (config === void 0) {
11 config = defaultThrottleConfig;
13 return function (source) { return source.lift(new ThrottleOperator(durationSelector, config.leading, config.trailing)); };
15 var ThrottleOperator = /*@__PURE__*/ (function () {
16 function ThrottleOperator(durationSelector, leading, trailing) {
17 this.durationSelector = durationSelector;
18 this.leading = leading;
19 this.trailing = trailing;
21 ThrottleOperator.prototype.call = function (subscriber, source) {
22 return source.subscribe(new ThrottleSubscriber(subscriber, this.durationSelector, this.leading, this.trailing));
24 return ThrottleOperator;
26 var ThrottleSubscriber = /*@__PURE__*/ (function (_super) {
27 tslib_1.__extends(ThrottleSubscriber, _super);
28 function ThrottleSubscriber(destination, durationSelector, _leading, _trailing) {
29 var _this = _super.call(this, destination) || this;
30 _this.destination = destination;
31 _this.durationSelector = durationSelector;
32 _this._leading = _leading;
33 _this._trailing = _trailing;
34 _this._hasValue = false;
37 ThrottleSubscriber.prototype._next = function (value) {
38 this._hasValue = true;
39 this._sendValue = value;
40 if (!this._throttled) {
49 ThrottleSubscriber.prototype.send = function () {
50 var _a = this, _hasValue = _a._hasValue, _sendValue = _a._sendValue;
52 this.destination.next(_sendValue);
53 this.throttle(_sendValue);
55 this._hasValue = false;
56 this._sendValue = null;
58 ThrottleSubscriber.prototype.throttle = function (value) {
59 var duration = this.tryDurationSelector(value);
61 this.add(this._throttled = subscribeToResult(this, duration));
64 ThrottleSubscriber.prototype.tryDurationSelector = function (value) {
66 return this.durationSelector(value);
69 this.destination.error(err);
73 ThrottleSubscriber.prototype.throttlingDone = function () {
74 var _a = this, _throttled = _a._throttled, _trailing = _a._trailing;
76 _throttled.unsubscribe();
78 this._throttled = null;
83 ThrottleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
84 this.throttlingDone();
86 ThrottleSubscriber.prototype.notifyComplete = function () {
87 this.throttlingDone();
89 return ThrottleSubscriber;
91 //# sourceMappingURL=throttle.js.map