Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / rxjs / internal / operators / windowToggle.js
1 "use strict";
2 var __extends = (this && this.__extends) || (function () {
3     var extendStatics = function (d, b) {
4         extendStatics = Object.setPrototypeOf ||
5             ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6             function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7         return extendStatics(d, b);
8     }
9     return function (d, b) {
10         extendStatics(d, b);
11         function __() { this.constructor = d; }
12         d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13     };
14 })();
15 Object.defineProperty(exports, "__esModule", { value: true });
16 var Subject_1 = require("../Subject");
17 var Subscription_1 = require("../Subscription");
18 var OuterSubscriber_1 = require("../OuterSubscriber");
19 var subscribeToResult_1 = require("../util/subscribeToResult");
20 function windowToggle(openings, closingSelector) {
21     return function (source) { return source.lift(new WindowToggleOperator(openings, closingSelector)); };
22 }
23 exports.windowToggle = windowToggle;
24 var WindowToggleOperator = (function () {
25     function WindowToggleOperator(openings, closingSelector) {
26         this.openings = openings;
27         this.closingSelector = closingSelector;
28     }
29     WindowToggleOperator.prototype.call = function (subscriber, source) {
30         return source.subscribe(new WindowToggleSubscriber(subscriber, this.openings, this.closingSelector));
31     };
32     return WindowToggleOperator;
33 }());
34 var WindowToggleSubscriber = (function (_super) {
35     __extends(WindowToggleSubscriber, _super);
36     function WindowToggleSubscriber(destination, openings, closingSelector) {
37         var _this = _super.call(this, destination) || this;
38         _this.openings = openings;
39         _this.closingSelector = closingSelector;
40         _this.contexts = [];
41         _this.add(_this.openSubscription = subscribeToResult_1.subscribeToResult(_this, openings, openings));
42         return _this;
43     }
44     WindowToggleSubscriber.prototype._next = function (value) {
45         var contexts = this.contexts;
46         if (contexts) {
47             var len = contexts.length;
48             for (var i = 0; i < len; i++) {
49                 contexts[i].window.next(value);
50             }
51         }
52     };
53     WindowToggleSubscriber.prototype._error = function (err) {
54         var contexts = this.contexts;
55         this.contexts = null;
56         if (contexts) {
57             var len = contexts.length;
58             var index = -1;
59             while (++index < len) {
60                 var context_1 = contexts[index];
61                 context_1.window.error(err);
62                 context_1.subscription.unsubscribe();
63             }
64         }
65         _super.prototype._error.call(this, err);
66     };
67     WindowToggleSubscriber.prototype._complete = function () {
68         var contexts = this.contexts;
69         this.contexts = null;
70         if (contexts) {
71             var len = contexts.length;
72             var index = -1;
73             while (++index < len) {
74                 var context_2 = contexts[index];
75                 context_2.window.complete();
76                 context_2.subscription.unsubscribe();
77             }
78         }
79         _super.prototype._complete.call(this);
80     };
81     WindowToggleSubscriber.prototype._unsubscribe = function () {
82         var contexts = this.contexts;
83         this.contexts = null;
84         if (contexts) {
85             var len = contexts.length;
86             var index = -1;
87             while (++index < len) {
88                 var context_3 = contexts[index];
89                 context_3.window.unsubscribe();
90                 context_3.subscription.unsubscribe();
91             }
92         }
93     };
94     WindowToggleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
95         if (outerValue === this.openings) {
96             var closingNotifier = void 0;
97             try {
98                 var closingSelector = this.closingSelector;
99                 closingNotifier = closingSelector(innerValue);
100             }
101             catch (e) {
102                 return this.error(e);
103             }
104             var window_1 = new Subject_1.Subject();
105             var subscription = new Subscription_1.Subscription();
106             var context_4 = { window: window_1, subscription: subscription };
107             this.contexts.push(context_4);
108             var innerSubscription = subscribeToResult_1.subscribeToResult(this, closingNotifier, context_4);
109             if (innerSubscription.closed) {
110                 this.closeWindow(this.contexts.length - 1);
111             }
112             else {
113                 innerSubscription.context = context_4;
114                 subscription.add(innerSubscription);
115             }
116             this.destination.next(window_1);
117         }
118         else {
119             this.closeWindow(this.contexts.indexOf(outerValue));
120         }
121     };
122     WindowToggleSubscriber.prototype.notifyError = function (err) {
123         this.error(err);
124     };
125     WindowToggleSubscriber.prototype.notifyComplete = function (inner) {
126         if (inner !== this.openSubscription) {
127             this.closeWindow(this.contexts.indexOf(inner.context));
128         }
129     };
130     WindowToggleSubscriber.prototype.closeWindow = function (index) {
131         if (index === -1) {
132             return;
133         }
134         var contexts = this.contexts;
135         var context = contexts[index];
136         var window = context.window, subscription = context.subscription;
137         contexts.splice(index, 1);
138         window.complete();
139         subscription.unsubscribe();
140     };
141     return WindowToggleSubscriber;
142 }(OuterSubscriber_1.OuterSubscriber));
143 //# sourceMappingURL=windowToggle.js.map