# Code coverage report for RxJS/dist/cjs/util/subscribeToResult.js

## Statements: 65.57% (40 / 61) Branches: 55.56% (20 / 36) Functions: 66.67% (4 / 6) Lines: 67.24% (39 / 58) Ignored: none

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

    1
    1

    4

    1

    1

    1

    1

    1

    1

    1

    1

    1

    1
    505
    505

    505
    435
    4
    4
    4

    431

    70
    38
    95

    38
    38

    32
    26
    23
    18
    18

    3

    26
    6

    6
    6
    6

    6

    1'use strict';

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

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

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

    var _Observable2 = _interopRequireDefault(_Observable);

    var _utilSymbol_iterator = require('../util/Symbol_iterator');

    var _utilSymbol_iterator2 = _interopRequireDefault(_utilSymbol_iterator);

    var _utilSymbol_observable = require('../util/Symbol_observable');

    var _utilSymbol_observable2 = _interopRequireDefault(_utilSymbol_observable);

    var _InnerSubscriber = require('../InnerSubscriber');

    var _InnerSubscriber2 = _interopRequireDefault(_InnerSubscriber);

    var isArray = Array.isArray;

    function subscribeToResult(outerSubscriber, result, outerValue, outerIndex) {
        var destination = new _InnerSubscriber2['default'](outerSubscriber, outerValue, outerIndex);
        Iif (destination.isUnsubscribed) {
            return;
        }
        if (result instanceof _Observable2['default']) {
            if (result._isScalar) {
                destination.next(result.value);
                destination.complete();
                return;
            } else {
                return result.subscribe(destination);
            }
        }
        if (isArray(result)) {
            for (var i = 0, len = result.length; i < len && !destination.isUnsubscribed; i++) {
                destination.next(result[i]);
            }
            Eif (!destination.isUnsubscribed) {
                destination.complete();
            }
        } else if (typeof result.then === 'function') {
            result.then(function (x) {
                if (!destination.isUnsubscribed) {
                    destination.next(x);
                    destination.complete();
                }
            }, function (err) {
                return destination.error(err);
            }).then(null, function (err) {
                // Escaping the Promise trap: globally throw unhandled errors
                setTimeout(function () {
                    throw err;
                });
            });
            return destination;
        } else Iif (typeof result[_utilSymbol_iterator2['default']] === 'function') {
            for (var _iterator = result, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
                var _ref;

                if (_isArray) {
                    if (_i >= _iterator.length) break;
                    _ref = _iterator[_i++];
                } else {
                    _i = _iterator.next();
                    if (_i.done) break;
                    _ref = _i.value;
                }

                var item = _ref;

                destination.next(item);
                if (destination.isUnsubscribed) {
                    break;
                }
            }
            if (!destination.isUnsubscribed) {
                destination.complete();
            }
        } else Eif (typeof result[_utilSymbol_observable2['default']] === 'function') {
            var obs = result[_utilSymbol_observable2['default']]();
            Iif (typeof obs.subscribe !== 'function') {
                destination.error('invalid observable');
            } else {
                return obs.subscribe(new _InnerSubscriber2['default'](outerSubscriber, outerValue, outerIndex));
            }
        } else {
            destination.error(new TypeError('unknown type returned'));
        }
    }

    module.exports = exports['default'];