# Code coverage report for RxJS/dist/cjs/operators/windowToggle.js

## Statements: 91.18% (93 / 102) Branches: 61.11% (11 / 18) Functions: 83.33% (20 / 24) Lines: 92.55% (87 / 94) Ignored: none

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

    1
    1

    4

    3

    6

    1

    1

    1

    1

    1

    1

    1

    1

    1

    1
    1

    1
    1
    1

    1
    1

    1
    1

    1

    1
    1

    1
    1

    1
    1
    1
    1
    1

    1
    8
    8
    8
    7

    1

    1
    1
    1
    1

    1

    1
    3
    3
    3
    3

    3
    3
    3

    3
    3
    3

    1
    3
    3

    3
    3
    3
    3

    1

    1
    1

    1
    3

    3
    3
    3

    1
    3

    1

    1

    1

    1
    1

    1
    1

    1
    1

    1
    3

    1

    1

    1

    1'use strict';

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

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

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

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

    var _Subscriber4 = require('../Subscriber');

    var _Subscriber5 = _interopRequireDefault(_Subscriber4);

    var _Subject = require('../Subject');

    var _Subject2 = _interopRequireDefault(_Subject);

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

    var _Subscription2 = _interopRequireDefault(_Subscription);

    var _utilTryCatch = require('../util/tryCatch');

    var _utilTryCatch2 = _interopRequireDefault(_utilTryCatch);

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

    function windowToggle(openings, closingSelector) {
        return this.lift(new WindowToggleOperator(openings, closingSelector));
    }

    var WindowToggleOperator = (function () {
        function WindowToggleOperator(openings, closingSelector) {
            _classCallCheck(this, WindowToggleOperator);

            this.openings = openings;
            this.closingSelector = closingSelector;
        }

        WindowToggleOperator.prototype.call = function call(subscriber) {
            return new WindowToggleSubscriber(subscriber, this.openings, this.closingSelector);
        };

        return WindowToggleOperator;
    })();

    var WindowToggleSubscriber = (function (_Subscriber) {
        _inherits(WindowToggleSubscriber, _Subscriber);

        function WindowToggleSubscriber(destination, openings, closingSelector) {
            _classCallCheck(this, WindowToggleSubscriber);

            _Subscriber.call(this, destination);
            this.openings = openings;
            this.closingSelector = closingSelector;
            this.windows = [];
            this.add(this.openings._subscribe(new WindowToggleOpeningsSubscriber(this)));
        }

        WindowToggleSubscriber.prototype._next = function _next(value) {
            var windows = this.windows;
            var len = windows.length;
            for (var i = 0; i < len; i++) {
                windows[i].next(value);
            }
        };

        WindowToggleSubscriber.prototype._error = function _error(err) {
            var windows = this.windows;
            while (windows.length > 0) {
                windows.shift().error(err);
            }
            this.destination.error(err);
        };

        WindowToggleSubscriber.prototype._complete = function _complete() {
            var windows = this.windows;
            while (windows.length > 0) {
                windows.shift().complete();
            }
            this.destination.complete();
        };

        WindowToggleSubscriber.prototype.openWindow = function openWindow(value) {
            var window = new _Subject2['default']();
            this.windows.push(window);
            this.destination.next(window);
            var windowContext = {
                window: window,
                subscription: new _Subscription2['default']()
            };
            var closingSelector = this.closingSelector;
            var closingNotifier = _utilTryCatch2['default'](closingSelector)(value);
            Iif (closingNotifier === _utilErrorObject.errorObject) {
                this.error(closingNotifier.e);
            } else {
                var subscriber = new WindowClosingNotifierSubscriber(this, windowContext);
                var subscription = closingNotifier._subscribe(subscriber);
                this.add(windowContext.subscription.add(subscription));
            }
        };

        WindowToggleSubscriber.prototype.closeWindow = function closeWindow(windowContext) {
            var window = windowContext.window;
            var subscription = windowContext.subscription;

            var windows = this.windows;
            windows.splice(windows.indexOf(window), 1);
            window.complete();
            this.remove(subscription);
        };

        return WindowToggleSubscriber;
    })(_Subscriber5['default']);

    var WindowClosingNotifierSubscriber = (function (_Subscriber2) {
        _inherits(WindowClosingNotifierSubscriber, _Subscriber2);

        function WindowClosingNotifierSubscriber(parent, windowContext) {
            _classCallCheck(this, WindowClosingNotifierSubscriber);

            _Subscriber2.call(this, null);
            this.parent = parent;
            this.windowContext = windowContext;
        }

        WindowClosingNotifierSubscriber.prototype._next = function _next() {
            this.parent.closeWindow(this.windowContext);
        };

        WindowClosingNotifierSubscriber.prototype._error = function _error(err) {
            this.parent.error(err);
        };

        WindowClosingNotifierSubscriber.prototype._complete = function _complete() {
            // noop
        };

        return WindowClosingNotifierSubscriber;
    })(_Subscriber5['default']);

    var WindowToggleOpeningsSubscriber = (function (_Subscriber3) {
        _inherits(WindowToggleOpeningsSubscriber, _Subscriber3);

        function WindowToggleOpeningsSubscriber(parent) {
            _classCallCheck(this, WindowToggleOpeningsSubscriber);

            _Subscriber3.call(this);
            this.parent = parent;
        }

        WindowToggleOpeningsSubscriber.prototype._next = function _next(value) {
            this.parent.openWindow(value);
        };

        WindowToggleOpeningsSubscriber.prototype._error = function _error(err) {
            this.parent.error(err);
        };

        WindowToggleOpeningsSubscriber.prototype._complete = function _complete() {
            // noop
        };

        return WindowToggleOpeningsSubscriber;
    })(_Subscriber5['default']);

    module.exports = exports['default'];