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

## Statements: 93.06% (134 / 144) Branches: 80.43% (37 / 46) Functions: 84.62% (22 / 26) Lines: 94.12% (128 / 136) Ignored: none

All files » RxJS/dist/cjs/ » Subject.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
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216

    1

    4

    1625

    2

    1

    1

    1

    1

    1

    1

    1

    1

    1
    1
    1
    1
    1
    1
    1
    1
    1

    1
    1

    1
    1236

    1236

    1236
    1236
    1236
    1236
    1236
    1236

    1
    1

    1
    388
    388
    388

    1
    874
    3
    871
    3
    2
    868
    5
    4
    863

    863
    863

    1

    1

    1
    748
    748

    1
    2590
    14

    2576
    2576
    2576
    2576

    2576
    26

    1
    176
    14

    162
    162
    162

    162
    162

    1
    657
    51

    606
    606
    26

    580
    580

    1
    2576
    2576
    2576
    2576
    2116

    1
    162
    162
    162

    162
    162
    162
    153

    162

    1
    580
    580
    580

    580
    580
    580
    425

    580

    1

    1

    1
    1

    1
    389

    389
    389
    389

    1
    389
    389

    1
    3

    1

    1
    1

    1
    3

    1

    1
    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 _Subscriber = require('./Subscriber');

    var _Subscriber2 = _interopRequireDefault(_Subscriber);

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

    var _Subscription2 = _interopRequireDefault(_Subscription);

    var _subjectsSubjectSubscription = require('./subjects/SubjectSubscription');

    var _subjectsSubjectSubscription2 = _interopRequireDefault(_subjectsSubjectSubscription);

    var subscriptionAdd = _Subscription2['default'].prototype.add;
    var subscriptionRemove = _Subscription2['default'].prototype.remove;
    var subscriptionUnsubscribe = _Subscription2['default'].prototype.unsubscribe;
    var subscriberNext = _Subscriber2['default'].prototype.next;
    var subscriberError = _Subscriber2['default'].prototype.error;
    var subscriberComplete = _Subscriber2['default'].prototype.complete;
    var _subscriberNext = _Subscriber2['default'].prototype._next;
    var _subscriberError = _Subscriber2['default'].prototype._error;
    var _subscriberComplete = _Subscriber2['default'].prototype._complete;

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

        function Subject() {
            _classCallCheck(this, Subject);

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

            _Observable.call.apply(_Observable, [this].concat(args));
            this.observers = [];
            this.isUnsubscribed = false;
            this.dispatching = false;
            this.errorSignal = false;
            this.completeSignal = false;
        }

        Subject.create = function create(source, destination) {
            return new BidirectionalSubject(source, destination);
        };

        Subject.prototype.lift = function lift(operator) {
            var subject = new BidirectionalSubject(this, this.destination || this);
            subject.operator = operator;
            return subject;
        };

        Subject.prototype._subscribe = function _subscribe(subscriber) {
            if (subscriber.isUnsubscribed) {
                return;
            } else if (this.errorSignal) {
                subscriber.error(this.errorInstance);
                return;
            } else if (this.completeSignal) {
                subscriber.complete();
                return;
            } else Iif (this.isUnsubscribed) {
                throw new Error("Cannot subscribe to a disposed Subject.");
            }
            this.observers.push(subscriber);
            return new _subjectsSubjectSubscription2['default'](this, subscriber);
        };

        Subject.prototype.add = function add(subscription) {
            subscriptionAdd.call(this, subscription);
        };

        Subject.prototype.remove = function remove(subscription) {
            subscriptionRemove.call(this, subscription);
        };

        Subject.prototype.unsubscribe = function unsubscribe() {
            this.observers = void 0;
            subscriptionUnsubscribe.call(this);
        };

        Subject.prototype.next = function next(value) {
            if (this.isUnsubscribed) {
                return;
            }
            this.dispatching = true;
            this._next(value);
            this.dispatching = false;
            Iif (this.errorSignal) {
                this.error(this.errorInstance);
            } else if (this.completeSignal) {
                this.complete();
            }
        };

        Subject.prototype.error = function error(_error) {
            if (this.isUnsubscribed || this.completeSignal) {
                return;
            }
            this.errorSignal = true;
            this.errorInstance = _error;
            Iif (this.dispatching) {
                return;
            }
            this._error(_error);
            this.unsubscribe();
        };

        Subject.prototype.complete = function complete() {
            if (this.isUnsubscribed || this.errorSignal) {
                return;
            }
            this.completeSignal = true;
            if (this.dispatching) {
                return;
            }
            this._complete();
            this.unsubscribe();
        };

        Subject.prototype._next = function _next(value) {
            var index = -1;
            var observers = this.observers.slice(0);
            var len = observers.length;
            while (++index < len) {
                observers[index].next(value);
            }
        };

        Subject.prototype._error = function _error(error) {
            var index = -1;
            var observers = this.observers;
            var len = observers.length;
            // optimization -- block next, complete, and unsubscribe while dispatching
            this.observers = void 0;
            this.isUnsubscribed = true;
            while (++index < len) {
                observers[index].error(error);
            }
            this.isUnsubscribed = false;
        };

        Subject.prototype._complete = function _complete() {
            var index = -1;
            var observers = this.observers;
            var len = observers.length;
            // optimization -- block next, complete, and unsubscribe while dispatching
            this.observers = void 0; // optimization
            this.isUnsubscribed = true;
            while (++index < len) {
                observers[index].complete();
            }
            this.isUnsubscribed = false;
        };

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

    exports['default'] = Subject;

    var BidirectionalSubject = (function (_Subject) {
        _inherits(BidirectionalSubject, _Subject);

        function BidirectionalSubject(source, destination) {
            _classCallCheck(this, BidirectionalSubject);

            _Subject.call(this);
            this.source = source;
            this.destination = destination;
        }

        BidirectionalSubject.prototype._subscribe = function _subscribe(subscriber) {
            var operator = this.operator;
            return this.source._subscribe.call(this.source, operator ? operator.call(subscriber) : subscriber);
        };

        BidirectionalSubject.prototype.next = function next(x) {
            subscriberNext.call(this, x);
        };

        BidirectionalSubject.prototype.error = function error(e) {
            subscriberError.call(this, e);
        };

        BidirectionalSubject.prototype.complete = function complete() {
            subscriberComplete.call(this);
        };

        BidirectionalSubject.prototype._next = function _next(x) {
            _subscriberNext.call(this, x);
        };

        BidirectionalSubject.prototype._error = function _error(e) {
            _subscriberError.call(this, e);
        };

        BidirectionalSubject.prototype._complete = function _complete() {
            _subscriberComplete.call(this);
        };

        return BidirectionalSubject;
    })(Subject);

    module.exports = exports['default'];