Code coverage report for RxJS/dist/cjs/operators/windowCount.js

Statements: 96.88% (62 / 64)      Branches: 78.57% (22 / 28)      Functions: 100% (12 / 12)      Lines: 100% (56 / 56)      Ignored: none     

All files » RxJS/dist/cjs/operators/ » windowCount.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    1 1   2   1   14   1   1   1   1   1 7   7     1 1 7   7 7     1 7     1     1 1   1 7   7 7 7 7 7 7     1 19 19 19 19 19 33   19 19 12   19 16 16 16       1 2 2 4   2     1 3 3 4   3     1     1
'use strict';
 
exports.__esModule = true;
exports['default'] = windowCount;
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
 
function _inherits(subClass, superClass) { Iif (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); Eif (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
 
function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
 
var _Subscriber2 = require('../Subscriber');
 
var _Subscriber3 = _interopRequireDefault(_Subscriber2);
 
var _Subject = require('../Subject');
 
var _Subject2 = _interopRequireDefault(_Subject);
 
function windowCount(windowSize) {
    var startWindowEvery = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
 
    return this.lift(new WindowCountOperator(windowSize, startWindowEvery));
}
 
var WindowCountOperator = (function () {
    function WindowCountOperator(windowSize, startWindowEvery) {
        _classCallCheck(this, WindowCountOperator);
 
        this.windowSize = windowSize;
        this.startWindowEvery = startWindowEvery;
    }
 
    WindowCountOperator.prototype.call = function call(subscriber) {
        return new WindowCountSubscriber(subscriber, this.windowSize, this.startWindowEvery);
    };
 
    return WindowCountOperator;
})();
 
var WindowCountSubscriber = (function (_Subscriber) {
    _inherits(WindowCountSubscriber, _Subscriber);
 
    function WindowCountSubscriber(destination, windowSize, startWindowEvery) {
        _classCallCheck(this, WindowCountSubscriber);
 
        _Subscriber.call(this, destination);
        this.windowSize = windowSize;
        this.startWindowEvery = startWindowEvery;
        this.windows = [new _Subject2['default']()];
        this.count = 0;
        destination.next(this.windows[0]);
    }
 
    WindowCountSubscriber.prototype._next = function _next(value) {
        var startWindowEvery = this.startWindowEvery > 0 ? this.startWindowEvery : this.windowSize;
        var windowSize = this.windowSize;
        var windows = this.windows;
        var len = windows.length;
        for (var i = 0; i < len; i++) {
            windows[i].next(value);
        }
        var c = this.count - windowSize + 1;
        if (c >= 0 && c % startWindowEvery === 0) {
            windows.shift().complete();
        }
        if (++this.count % startWindowEvery === 0) {
            var _window = new _Subject2['default']();
            windows.push(_window);
            this.destination.next(_window);
        }
    };
 
    WindowCountSubscriber.prototype._error = function _error(err) {
        var windows = this.windows;
        while (windows.length > 0) {
            windows.shift().error(err);
        }
        this.destination.error(err);
    };
 
    WindowCountSubscriber.prototype._complete = function _complete() {
        var windows = this.windows;
        while (windows.length > 0) {
            windows.shift().complete();
        }
        this.destination.complete();
    };
 
    return WindowCountSubscriber;
})(_Subscriber3['default']);
 
module.exports = exports['default'];