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

## Statements: 91.94% (57 / 62) Branches: 75% (27 / 36) Functions: 100% (13 / 13) Lines: 94.44% (51 / 54) Ignored: none

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

    1

    3

    5

    1

    1

    1

    1

    1

    1

    1

    1

    1
    1

    1
    5

    5
    5
    5
    5

    1
    5

    1
    5
    5
    5

    5
    1
    1
    1

    4
    3
    3
    1

    1
    1
    1
    1

    5

    1
    5
    5
    5
    5
    1
    1

    1

    1

    5

    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 _utilTryCatch = require('../util/tryCatch');

    var _utilTryCatch2 = _interopRequireDefault(_utilTryCatch);

    var _utilErrorObject = require('../util/errorObject');

    var _Subscription = require('../Subscription');

    var _Subscription2 = _interopRequireDefault(_Subscription);

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

        function FromEventObservable(sourceObj, eventName, selector) {
            _classCallCheck(this, FromEventObservable);

            _Observable.call(this);
            this.sourceObj = sourceObj;
            this.eventName = eventName;
            this.selector = selector;
        }

        FromEventObservable.create = function create(sourceObj, eventName, selector) {
            return new FromEventObservable(sourceObj, eventName, selector);
        };

        FromEventObservable.setupSubscription = function setupSubscription(sourceObj, eventName, handler, subscriber) {
            var unsubscribe = undefined;
            var tag = sourceObj.toString();
            Iif (tag === '[object NodeList]' || tag === '[object HTMLCollection]') {
                for (var i = 0, len = sourceObj.length; i < len; i++) {
                    FromEventObservable.setupSubscription(sourceObj[i], eventName, handler, subscriber);
                }
            } else if (typeof sourceObj.addEventListener === 'function' && typeof sourceObj.removeEventListener === 'function') {
                sourceObj.addEventListener(eventName, handler);
                unsubscribe = function () {
                    return sourceObj.removeEventListener(eventName, handler);
                };
            } else if (typeof sourceObj.on === 'function' && typeof sourceObj.off === 'function') {
                sourceObj.on(eventName, handler);
                unsubscribe = function () {
                    return sourceObj.off(eventName, handler);
                };
            } else Eif (typeof sourceObj.addListener === 'function' && typeof sourceObj.removeListener === 'function') {
                sourceObj.addListener(eventName, handler);
                unsubscribe = function () {
                    return sourceObj.removeListener(eventName, handler);
                };
            }
            subscriber.add(new _Subscription2['default'](unsubscribe));
        };

        FromEventObservable.prototype._subscribe = function _subscribe(subscriber) {
            var sourceObj = this.sourceObj;
            var eventName = this.eventName;
            var selector = this.selector;
            var handler = selector ? function (e) {
                var result = _utilTryCatch2['default'](selector)(e);
                Iif (result === _utilErrorObject.errorObject) {
                    subscriber.error(result.e);
                } else {
                    subscriber.next(result);
                }
            } : function (e) {
                return subscriber.next(e);
            };
            FromEventObservable.setupSubscription(sourceObj, eventName, handler, subscriber);
        };

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

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