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 Subscriber_1 = require("../Subscriber");
17 var async_1 = require("../scheduler/async");
18 var throttle_1 = require("./throttle");
19 function throttleTime(duration, scheduler, config) {
20 if (scheduler === void 0) { scheduler = async_1.async; }
21 if (config === void 0) { config = throttle_1.defaultThrottleConfig; }
22 return function (source) { return source.lift(new ThrottleTimeOperator(duration, scheduler, config.leading, config.trailing)); };
24 exports.throttleTime = throttleTime;
25 var ThrottleTimeOperator = (function () {
26 function ThrottleTimeOperator(duration, scheduler, leading, trailing) {
27 this.duration = duration;
28 this.scheduler = scheduler;
29 this.leading = leading;
30 this.trailing = trailing;
32 ThrottleTimeOperator.prototype.call = function (subscriber, source) {
33 return source.subscribe(new ThrottleTimeSubscriber(subscriber, this.duration, this.scheduler, this.leading, this.trailing));
35 return ThrottleTimeOperator;
37 var ThrottleTimeSubscriber = (function (_super) {
38 __extends(ThrottleTimeSubscriber, _super);
39 function ThrottleTimeSubscriber(destination, duration, scheduler, leading, trailing) {
40 var _this = _super.call(this, destination) || this;
41 _this.duration = duration;
42 _this.scheduler = scheduler;
43 _this.leading = leading;
44 _this.trailing = trailing;
45 _this._hasTrailingValue = false;
46 _this._trailingValue = null;
49 ThrottleTimeSubscriber.prototype._next = function (value) {
52 this._trailingValue = value;
53 this._hasTrailingValue = true;
57 this.add(this.throttled = this.scheduler.schedule(dispatchNext, this.duration, { subscriber: this }));
59 this.destination.next(value);
61 else if (this.trailing) {
62 this._trailingValue = value;
63 this._hasTrailingValue = true;
67 ThrottleTimeSubscriber.prototype._complete = function () {
68 if (this._hasTrailingValue) {
69 this.destination.next(this._trailingValue);
70 this.destination.complete();
73 this.destination.complete();
76 ThrottleTimeSubscriber.prototype.clearThrottle = function () {
77 var throttled = this.throttled;
79 if (this.trailing && this._hasTrailingValue) {
80 this.destination.next(this._trailingValue);
81 this._trailingValue = null;
82 this._hasTrailingValue = false;
84 throttled.unsubscribe();
85 this.remove(throttled);
86 this.throttled = null;
89 return ThrottleTimeSubscriber;
90 }(Subscriber_1.Subscriber));
91 function dispatchNext(arg) {
92 var subscriber = arg.subscriber;
93 subscriber.clearThrottle();
95 //# sourceMappingURL=throttleTime.js.map