# Code coverage report for RxJS/dist/cjs/Subscription.js

## Statements: 96.23% (51 / 53) Branches: 94.29% (33 / 35) Functions: 100% (8 / 8) Lines: 98.04% (50 / 51) Ignored: none

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

    1

    12449

    1
    1
    12449

    12449
    12449
    873

    1

    1
    4232
    4

    4228
    4228
    4228
    4228
    4228
    3484

    4228
    1377
    1377
    1377
    3047

    1

    4505
    806

    3699
    3699

    6

    3699
    65
    3634
    50

    3584
    3584

    3634

    1

    339
    22

    317
    317
    273
    273
    236

    1

    1

    1
    1
    1

    1"use strict";

    exports.__esModule = true;

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

    var Subscription = (function () {
        function Subscription(_unsubscribe) {
            _classCallCheck(this, Subscription);

            this.isUnsubscribed = false;
            if (_unsubscribe) {
                this._unsubscribe = _unsubscribe;
            }
        }

        Subscription.prototype._unsubscribe = function _unsubscribe() {};

        Subscription.prototype.unsubscribe = function unsubscribe() {
            if (this.isUnsubscribed) {
                return;
            }
            this.isUnsubscribed = true;
            var unsubscribe = this._unsubscribe;
            var subscriptions = this._subscriptions;
            this._subscriptions = void 0;
            if (unsubscribe) {
                unsubscribe.call(this);
            }
            if (subscriptions != null) {
                var index = -1;
                var len = subscriptions.length;
                while (++index < len) {
                    subscriptions[index].unsubscribe();
                }
            }
        };

        Subscription.prototype.add = function add(subscription) {
            // return early if:
            //  1. the subscription is null
            //  2. we're attempting to add our this
            //  3. we're attempting to add the static `empty` Subscription
            if (!subscription || subscription === this || subscription === Subscription.EMPTY) {
                return;
            }
            var sub = subscription;
            switch (typeof subscription) {
                case "function":
                    sub = new Subscription(subscription);
                case "object":
                    if (sub.isUnsubscribed || typeof sub.unsubscribe !== "function") {
                        break;
                    } else if (this.isUnsubscribed) {
                        sub.unsubscribe();
                    } else {
                        var subscriptions = this._subscriptions || (this._subscriptions = []);
                        subscriptions.push(sub);
                    }
                    break;
                default:
                    throw new Error('Unrecognized subscription ' + subscription + ' added to Subscription.');
            }
        };

        Subscription.prototype.remove = function remove(subscription) {
            // return early if:
            //  1. the subscription is null
            //  2. we're attempting to remove ourthis
            //  3. we're attempting to remove the static `empty` Subscription
            if (subscription == null || subscription === this || subscription === Subscription.EMPTY) {
                return;
            }
            var subscriptions = this._subscriptions;
            if (subscriptions) {
                var subscriptionIndex = subscriptions.indexOf(subscription);
                if (subscriptionIndex !== -1) {
                    subscriptions.splice(subscriptionIndex, 1);
                }
            }
        };

        return Subscription;
    })();

    exports["default"] = Subscription;

    Subscription.EMPTY = (function (empty) {
        empty.isUnsubscribed = true;
        return empty;
    })(new Subscription());
    module.exports = exports["default"];