Code coverage report for cjs/operator/debounce.js

Statements: 100% (76 / 76)      Branches: 89.47% (17 / 19)      Functions: 100% (19 / 19)      Lines: 100% (73 / 73)      Ignored: none     

All files » cjs/operator/ » debounce.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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 1041 4 2 2   1 1 1 1 1 1 24   1 1 1 24   1 24   1   1 1 1 24 24 24 24 24   1   75         1 89 89 89 89 1     88 7   88 88 88     1 13 13   1 70 70 59 59     1 158 158 30 30 30     1   1 1 1 88 88 88   1 75 75 57 57 34       1 48   1 2   1 27   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 debounce(durationSelector) {
    return this.lift(new DebounceOperator(durationSelector));
}
exports.debounce = debounce;
var DebounceOperator = (function () {
    function DebounceOperator(durationSelector) {
        this.durationSelector = durationSelector;
    }
    DebounceOperator.prototype.call = function (observer) {
        return new DebounceSubscriber(observer, this.durationSelector);
    };
    return DebounceOperator;
})();
var DebounceSubscriber = (function (_super) {
    __extends(DebounceSubscriber, _super);
    function DebounceSubscriber(destination, durationSelector) {
        _super.call(this, destination);
        this.durationSelector = durationSelector;
        this.debouncedSubscription = null;
        this.lastValue = null;
        this._index = 0;
    }
    Object.defineProperty(DebounceSubscriber.prototype, "index", {
        get: function () {
            return this._index;
        },
        enumerable: true,
        configurable: true
    });
    DebounceSubscriber.prototype._next = function (value) {
        var destination = this.destination;
        var currentIndex = ++this._index;
        var debounce = tryCatch_1.tryCatch(this.durationSelector)(value);
        if (debounce === errorObject_1.errorObject) {
            destination.error(errorObject_1.errorObject.e);
        }
        else {
            if (isPromise_1.isPromise(debounce)) {
                debounce = fromPromise_1.PromiseObservable.create(debounce);
            }
            this.lastValue = value;
            this.clearDebounce();
            this.add(this.debouncedSubscription = debounce._subscribe(new DurationSelectorSubscriber(this, currentIndex)));
        }
    };
    DebounceSubscriber.prototype._complete = function () {
        this.debouncedNext();
        this.destination.complete();
    };
    DebounceSubscriber.prototype.debouncedNext = function () {
        this.clearDebounce();
        if (this.lastValue != null) {
            this.destination.next(this.lastValue);
            this.lastValue = null;
        }
    };
    DebounceSubscriber.prototype.clearDebounce = function () {
        var debouncedSubscription = this.debouncedSubscription;
        if (debouncedSubscription) {
            debouncedSubscription.unsubscribe();
            this.remove(debouncedSubscription);
            this.debouncedSubscription = null;
        }
    };
    return DebounceSubscriber;
})(Subscriber_1.Subscriber);
var DurationSelectorSubscriber = (function (_super) {
    __extends(DurationSelectorSubscriber, _super);
    function DurationSelectorSubscriber(parent, currentIndex) {
        _super.call(this, null);
        this.parent = parent;
        this.currentIndex = currentIndex;
    }
    DurationSelectorSubscriber.prototype.debounceNext = function () {
        var parent = this.parent;
        if (this.currentIndex === parent.index) {
            parent.debouncedNext();
            if (!this.isUnsubscribed) {
                this.unsubscribe();
            }
        }
    };
    DurationSelectorSubscriber.prototype._next = function (unused) {
        this.debounceNext();
    };
    DurationSelectorSubscriber.prototype._error = function (err) {
        this.parent.error(err);
    };
    DurationSelectorSubscriber.prototype._complete = function () {
        this.debounceNext();
    };
    return DurationSelectorSubscriber;
})(Subscriber_1.Subscriber);
//# sourceMappingURL=debounce.js.map