1 /** PURE_IMPORTS_START tslib,_Subscriber,_scheduler_async,_throttle PURE_IMPORTS_END */
2 import * as tslib_1 from "tslib";
3 import { Subscriber } from '../Subscriber';
4 import { async } from '../scheduler/async';
5 import { defaultThrottleConfig } from './throttle';
6 export function throttleTime(duration, scheduler, config) {
7 if (scheduler === void 0) {
10 if (config === void 0) {
11 config = defaultThrottleConfig;
13 return function (source) { return source.lift(new ThrottleTimeOperator(duration, scheduler, config.leading, config.trailing)); };
15 var ThrottleTimeOperator = /*@__PURE__*/ (function () {
16 function ThrottleTimeOperator(duration, scheduler, leading, trailing) {
17 this.duration = duration;
18 this.scheduler = scheduler;
19 this.leading = leading;
20 this.trailing = trailing;
22 ThrottleTimeOperator.prototype.call = function (subscriber, source) {
23 return source.subscribe(new ThrottleTimeSubscriber(subscriber, this.duration, this.scheduler, this.leading, this.trailing));
25 return ThrottleTimeOperator;
27 var ThrottleTimeSubscriber = /*@__PURE__*/ (function (_super) {
28 tslib_1.__extends(ThrottleTimeSubscriber, _super);
29 function ThrottleTimeSubscriber(destination, duration, scheduler, leading, trailing) {
30 var _this = _super.call(this, destination) || this;
31 _this.duration = duration;
32 _this.scheduler = scheduler;
33 _this.leading = leading;
34 _this.trailing = trailing;
35 _this._hasTrailingValue = false;
36 _this._trailingValue = null;
39 ThrottleTimeSubscriber.prototype._next = function (value) {
42 this._trailingValue = value;
43 this._hasTrailingValue = true;
47 this.add(this.throttled = this.scheduler.schedule(dispatchNext, this.duration, { subscriber: this }));
49 this.destination.next(value);
51 else if (this.trailing) {
52 this._trailingValue = value;
53 this._hasTrailingValue = true;
57 ThrottleTimeSubscriber.prototype._complete = function () {
58 if (this._hasTrailingValue) {
59 this.destination.next(this._trailingValue);
60 this.destination.complete();
63 this.destination.complete();
66 ThrottleTimeSubscriber.prototype.clearThrottle = function () {
67 var throttled = this.throttled;
69 if (this.trailing && this._hasTrailingValue) {
70 this.destination.next(this._trailingValue);
71 this._trailingValue = null;
72 this._hasTrailingValue = false;
74 throttled.unsubscribe();
75 this.remove(throttled);
76 this.throttled = null;
79 return ThrottleTimeSubscriber;
81 function dispatchNext(arg) {
82 var subscriber = arg.subscriber;
83 subscriber.clearThrottle();
85 //# sourceMappingURL=throttleTime.js.map