# Code coverage report for RxJS/dist/cjs/operators/reduce.js

## Statements: 96.08% (49 / 51) Branches: 76.92% (20 / 26) Functions: 100% (11 / 11) Lines: 100% (43 / 43) Ignored: none

All files » RxJS/dist/cjs/operators/ » reduce.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

    1
    1

    2

    1

    28

    1

    1

    1

    1

    1

    1
    14

    1
    1
    14

    14
    14

    1
    14

    1

    1
    1

    1
    14

    14
    14
    14
    14
    14

    1
    15
    12
    12
    2

    10

    3
    3

    1
    4
    3

    4

    1

    1'use strict';

    exports.__esModule = true;
    exports['default'] = reduce;

    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');

    function reduce(project, acc) {
        return this.lift(new ReduceOperator(project, acc));
    }

    var ReduceOperator = (function () {
        function ReduceOperator(project, acc) {
            _classCallCheck(this, ReduceOperator);

            this.acc = acc;
            this.project = project;
        }

        ReduceOperator.prototype.call = function call(subscriber) {
            return new ReduceSubscriber(subscriber, this.project, this.acc);
        };

        return ReduceOperator;
    })();

    var ReduceSubscriber = (function (_Subscriber) {
        _inherits(ReduceSubscriber, _Subscriber);

        function ReduceSubscriber(destination, project, acc) {
            _classCallCheck(this, ReduceSubscriber);

            _Subscriber.call(this, destination);
            this.hasValue = false;
            this.acc = acc;
            this.project = project;
            this.hasSeed = typeof acc !== 'undefined';
        }

        ReduceSubscriber.prototype._next = function _next(x) {
            if (this.hasValue || (this.hasValue = this.hasSeed)) {
                var result = _utilTryCatch2['default'](this.project).call(this, this.acc, x);
                if (result === _utilErrorObject.errorObject) {
                    this.destination.error(_utilErrorObject.errorObject.e);
                } else {
                    this.acc = result;
                }
            } else {
                this.acc = x;
                this.hasValue = true;
            }
        };

        ReduceSubscriber.prototype._complete = function _complete() {
            if (this.hasValue || this.hasSeed) {
                this.destination.next(this.acc);
            }
            this.destination.complete();
        };

        return ReduceSubscriber;
    })(_Subscriber3['default']);

    module.exports = exports['default'];