# Code coverage report for RxJS/dist/cjs/observables/ArrayObservable.js

## Statements: 94.2% (65 / 69) Branches: 80.56% (29 / 36) Functions: 100% (9 / 9) Lines: 96.72% (59 / 61) Ignored: none

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

    1

    3

    223

    1

    1

    1

    1

    1

    1

    1

    1
    1

    1
    223

    223
    223
    223
    223

    1
    42

    1
    121
    336

    121
    121
    22

    99

    121
    121
    81
    40
    38

    2

    1
    167
    167
    167
    167

    167
    40
    40

    127
    127
    3

    124
    124

    1
    230
    230
    230
    230
    230
    46

    184
    482

    184

    1

    1
    1'use strict';

    exports.__esModule = true;

    function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

    function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

    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; }

    var _Observable2 = require('../Observable');

    var _Observable3 = _interopRequireDefault(_Observable2);

    var _ScalarObservable = require('./ScalarObservable');

    var _ScalarObservable2 = _interopRequireDefault(_ScalarObservable);

    var _EmptyObservable = require('./EmptyObservable');

    var _EmptyObservable2 = _interopRequireDefault(_EmptyObservable);

    var ArrayObservable = (function (_Observable) {
        _inherits(ArrayObservable, _Observable);

        function ArrayObservable(array, scheduler) {
            _classCallCheck(this, ArrayObservable);

            _Observable.call(this);
            this.array = array;
            this.scheduler = scheduler;
            Iif (!scheduler && array.length === 1) {
                this._isScalar = true;
                this.value = array[0];
            }
        }

        ArrayObservable.create = function create(array, scheduler) {
            return new ArrayObservable(array, scheduler);
        };

        ArrayObservable.of = function of() {
            for (var _len = arguments.length, array = Array(_len), _key = 0; _key < _len; _key++) {
                array[_key] = arguments[_key];
            }

            var scheduler = array[array.length - 1];
            if (scheduler && typeof scheduler.schedule === 'function') {
                array.pop();
            } else {
                scheduler = void 0;
            }
            var len = array.length;
            if (len > 1) {
                return new ArrayObservable(array, scheduler);
            } else if (len === 1) {
                return new _ScalarObservable2['default'](array[0], scheduler);
            } else {
                return new _EmptyObservable2['default'](scheduler);
            }
        };

        ArrayObservable.dispatch = function dispatch(state) {
            var array = state.array;
            var index = state.index;
            var count = state.count;
            var subscriber = state.subscriber;

            if (index >= count) {
                subscriber.complete();
                return;
            }
            subscriber.next(array[index]);
            if (subscriber.isUnsubscribed) {
                return;
            }
            state.index = index + 1;
            this.schedule(state);
        };

        ArrayObservable.prototype._subscribe = function _subscribe(subscriber) {
            var index = 0;
            var array = this.array;
            var count = array.length;
            var scheduler = this.scheduler;
            if (scheduler) {
                subscriber.add(scheduler.schedule(ArrayObservable.dispatch, 0, {
                    array: array, index: index, count: count, subscriber: subscriber
                }));
            } else {
                for (var i = 0; i < count && !subscriber.isUnsubscribed; i++) {
                    subscriber.next(array[i]);
                }
                subscriber.complete();
            }
        };

        return ArrayObservable;
    })(_Observable3['default']);

    exports['default'] = ArrayObservable;
    module.exports = exports['default'];