source: trip-planner-front/node_modules/rxjs/_esm5/internal/operators/throttleTime.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/** PURE_IMPORTS_START tslib,_Subscriber,_scheduler_async,_throttle PURE_IMPORTS_END */
2import * as tslib_1 from "tslib";
3import { Subscriber } from '../Subscriber';
4import { async } from '../scheduler/async';
5import { defaultThrottleConfig } from './throttle';
6export function throttleTime(duration, scheduler, config) {
7 if (scheduler === void 0) {
8 scheduler = async;
9 }
10 if (config === void 0) {
11 config = defaultThrottleConfig;
12 }
13 return function (source) { return source.lift(new ThrottleTimeOperator(duration, scheduler, config.leading, config.trailing)); };
14}
15var 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;
21 }
22 ThrottleTimeOperator.prototype.call = function (subscriber, source) {
23 return source.subscribe(new ThrottleTimeSubscriber(subscriber, this.duration, this.scheduler, this.leading, this.trailing));
24 };
25 return ThrottleTimeOperator;
26}());
27var 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;
37 return _this;
38 }
39 ThrottleTimeSubscriber.prototype._next = function (value) {
40 if (this.throttled) {
41 if (this.trailing) {
42 this._trailingValue = value;
43 this._hasTrailingValue = true;
44 }
45 }
46 else {
47 this.add(this.throttled = this.scheduler.schedule(dispatchNext, this.duration, { subscriber: this }));
48 if (this.leading) {
49 this.destination.next(value);
50 }
51 else if (this.trailing) {
52 this._trailingValue = value;
53 this._hasTrailingValue = true;
54 }
55 }
56 };
57 ThrottleTimeSubscriber.prototype._complete = function () {
58 if (this._hasTrailingValue) {
59 this.destination.next(this._trailingValue);
60 this.destination.complete();
61 }
62 else {
63 this.destination.complete();
64 }
65 };
66 ThrottleTimeSubscriber.prototype.clearThrottle = function () {
67 var throttled = this.throttled;
68 if (throttled) {
69 if (this.trailing && this._hasTrailingValue) {
70 this.destination.next(this._trailingValue);
71 this._trailingValue = null;
72 this._hasTrailingValue = false;
73 }
74 throttled.unsubscribe();
75 this.remove(throttled);
76 this.throttled = null;
77 }
78 };
79 return ThrottleTimeSubscriber;
80}(Subscriber));
81function dispatchNext(arg) {
82 var subscriber = arg.subscriber;
83 subscriber.clearThrottle();
84}
85//# sourceMappingURL=throttleTime.js.map
Note: See TracBrowser for help on using the repository browser.