Code coverage report for cjs/operators/count.js

Statements: 96.49% (55 / 57)      Branches: 75% (18 / 24)      Functions: 100% (11 / 11)      Lines: 100% (49 / 49)      Ignored: none     

All files » cjs/operators/ » count.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    1 1   3   1   44   1   1   1   1   1   1   1                                 1 22     1 1 22   22 22 22     1 22     1     1 1   1 22   22 22 22 22 22 22 10           1 40 40 40 10 10 1 1     39 35       1 14 14     1     1  
'use strict';
 
exports.__esModule = true;
exports['default'] = count;
 
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 _utilTryCatch = require('../util/tryCatch');
 
var _utilTryCatch2 = _interopRequireDefault(_utilTryCatch);
 
var _utilErrorObject = require('../util/errorObject');
 
var _utilBindCallback = require('../util/bindCallback');
 
var _utilBindCallback2 = _interopRequireDefault(_utilBindCallback);
 
/**
 * Returns an observable of a single number that represents the number of items that either:
 * Match a provided predicate function, _or_ if a predicate is not provided, the number
 * represents the total count of all items in the source observable. The count is emitted
 * by the returned observable when the source observable completes.
 * @param {function} [predicate] a boolean function to select what values are to be counted.
 * it is provided with arguments of:
 *   - `value`: the value from the source observable
 *   - `index`: the "index" of the value from the source observable
 *   - `source`: the source observable instance itself.
 * @param {any} [thisArg] the optional `this` context to use in the `predicate` function
 * @returns {Observable} an observable of one number that represents the count as described
 * above
 */
 
function count(predicate, thisArg) {
    return this.lift(new CountOperator(predicate, thisArg, this));
}
 
var CountOperator = (function () {
    function CountOperator(predicate, thisArg, source) {
        _classCallCheck(this, CountOperator);
 
        this.predicate = predicate;
        this.thisArg = thisArg;
        this.source = source;
    }
 
    CountOperator.prototype.call = function call(subscriber) {
        return new CountSubscriber(subscriber, this.predicate, this.thisArg, this.source);
    };
 
    return CountOperator;
})();
 
var CountSubscriber = (function (_Subscriber) {
    _inherits(CountSubscriber, _Subscriber);
 
    function CountSubscriber(destination, predicate, thisArg, source) {
        _classCallCheck(this, CountSubscriber);
 
        _Subscriber.call(this, destination);
        this.thisArg = thisArg;
        this.source = source;
        this.count = 0;
        this.index = 0;
        if (typeof predicate === 'function') {
            this.predicate = _utilBindCallback2['default'](predicate, thisArg, 3);
        }
    }
 
    //# sourceMappingURL=count.js.map
 
    CountSubscriber.prototype._next = function _next(value) {
        var predicate = this.predicate;
        var passed = true;
        if (predicate) {
            passed = _utilTryCatch2['default'](predicate)(value, this.index++, this.source);
            if (passed === _utilErrorObject.errorObject) {
                this.destination.error(passed.e);
                return;
            }
        }
        if (passed) {
            this.count += 1;
        }
    };
 
    CountSubscriber.prototype._complete = function _complete() {
        this.destination.next(this.count);
        this.destination.complete();
    };
 
    return CountSubscriber;
})(_Subscriber3['default']);
 
module.exports = exports['default'];
//# sourceMappingURL=count.js.map