Code coverage report for cjs/operator/throttle.js

Statements: 100% (62 / 62)      Branches: 86.67% (13 / 15)      Functions: 100% (17 / 17)      Lines: 100% (59 / 59)      Ignored: none     

All files » cjs/operator/ » throttle.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 801 4 2 2   1 1 1 1 1 1 19   1 1 1 19   1 19   1   1 1 1 19 19   1 188 61 61 61 1 1   60 7   60 60     1 6 6   1 10 10   1 74 74 52 52 52     1   1 1 1 60 60   1 9   1 3   1 49   1    
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) Eif (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var fromPromise_1 = require('../observable/fromPromise');
var Subscriber_1 = require('../Subscriber');
var tryCatch_1 = require('../util/tryCatch');
var isPromise_1 = require('../util/isPromise');
var errorObject_1 = require('../util/errorObject');
function throttle(durationSelector) {
    return this.lift(new ThrottleOperator(durationSelector));
}
exports.throttle = throttle;
var ThrottleOperator = (function () {
    function ThrottleOperator(durationSelector) {
        this.durationSelector = durationSelector;
    }
    ThrottleOperator.prototype.call = function (subscriber) {
        return new ThrottleSubscriber(subscriber, this.durationSelector);
    };
    return ThrottleOperator;
})();
var ThrottleSubscriber = (function (_super) {
    __extends(ThrottleSubscriber, _super);
    function ThrottleSubscriber(destination, durationSelector) {
        _super.call(this, destination);
        this.durationSelector = durationSelector;
    }
    ThrottleSubscriber.prototype._next = function (value) {
        if (!this.throttled) {
            var destination = this.destination;
            var duration = tryCatch_1.tryCatch(this.durationSelector)(value);
            if (duration === errorObject_1.errorObject) {
                destination.error(errorObject_1.errorObject.e);
                return;
            }
            if (isPromise_1.isPromise(duration)) {
                duration = fromPromise_1.PromiseObservable.create(duration);
            }
            this.add(this.throttled = duration._subscribe(new ThrottleDurationSelectorSubscriber(this)));
            destination.next(value);
        }
    };
    ThrottleSubscriber.prototype._error = function (err) {
        this.clearThrottle();
        _super.prototype._error.call(this, err);
    };
    ThrottleSubscriber.prototype._complete = function () {
        this.clearThrottle();
        _super.prototype._complete.call(this);
    };
    ThrottleSubscriber.prototype.clearThrottle = function () {
        var throttled = this.throttled;
        if (throttled) {
            throttled.unsubscribe();
            this.remove(throttled);
            this.throttled = null;
        }
    };
    return ThrottleSubscriber;
})(Subscriber_1.Subscriber);
var ThrottleDurationSelectorSubscriber = (function (_super) {
    __extends(ThrottleDurationSelectorSubscriber, _super);
    function ThrottleDurationSelectorSubscriber(parent) {
        _super.call(this, null);
        this.parent = parent;
    }
    ThrottleDurationSelectorSubscriber.prototype._next = function (unused) {
        this.parent.clearThrottle();
    };
    ThrottleDurationSelectorSubscriber.prototype._error = function (err) {
        this.parent.error(err);
    };
    ThrottleDurationSelectorSubscriber.prototype._complete = function () {
        this.parent.clearThrottle();
    };
    return ThrottleDurationSelectorSubscriber;
})(Subscriber_1.Subscriber);
//# sourceMappingURL=throttle.js.map