Code coverage report for cjs/operator/takeLast.js

Statements: 96.55% (56 / 58)      Branches: 85.19% (23 / 27)      Functions: 100% (10 / 10)      Lines: 96.36% (53 / 55)      Ignored: none     

All files » cjs/operator/ » takeLast.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 781 2 1 1   1 1 1 1 13 1     12     1 1 1 12 12 1     1 11   1   1 1 1 11 11 11 11 11   1 14 14 14 14 14 10 8 8   2 1   1       1     4 2   14   1 5 5 5 5 4     4   5   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 Subscriber_1 = require('../Subscriber');
var ArgumentOutOfRangeError_1 = require('../util/ArgumentOutOfRangeError');
var EmptyObservable_1 = require('../observable/EmptyObservable');
function takeLast(total) {
    if (total === 0) {
        return new EmptyObservable_1.EmptyObservable();
    }
    else {
        return this.lift(new TakeLastOperator(total));
    }
}
exports.takeLast = takeLast;
var TakeLastOperator = (function () {
    function TakeLastOperator(total) {
        this.total = total;
        if (this.total < 0) {
            throw new ArgumentOutOfRangeError_1.ArgumentOutOfRangeError;
        }
    }
    TakeLastOperator.prototype.call = function (subscriber) {
        return new TakeLastSubscriber(subscriber, this.total);
    };
    return TakeLastOperator;
})();
var TakeLastSubscriber = (function (_super) {
    __extends(TakeLastSubscriber, _super);
    function TakeLastSubscriber(destination, total) {
        _super.call(this, destination);
        this.total = total;
        this.count = 0;
        this.index = 0;
        this.ring = new Array(total);
    }
    TakeLastSubscriber.prototype._next = function (value) {
        var index = this.index;
        var ring = this.ring;
        var total = this.total;
        var count = this.count;
        if (total > 1) {
            if (count < total) {
                this.count = count + 1;
                this.index = index + 1;
            }
            else if (index === 0) {
                this.index = ++index;
            }
            else Iif (index < total) {
                this.index = index + 1;
            }
            else {
                this.index = index = 0;
            }
        }
        else if (count < total) {
            this.count = total;
        }
        ring[index] = value;
    };
    TakeLastSubscriber.prototype._complete = function () {
        var iter = -1;
        var _a = this, ring = _a.ring, count = _a.count, total = _a.total, destination = _a.destination;
        var index = (total === 1 || count < total) ? 0 : this.index - 1;
        while (++iter < count) {
            Iif (iter + index === total) {
                index = total - iter;
            }
            destination.next(ring[iter + index]);
        }
        destination.complete();
    };
    return TakeLastSubscriber;
})(Subscriber_1.Subscriber);
//# sourceMappingURL=takeLast.js.map