1 /** PURE_IMPORTS_START tslib,_Subject,_Subscription,_OuterSubscriber,_util_subscribeToResult PURE_IMPORTS_END */
2 import * as tslib_1 from "tslib";
3 import { Subject } from '../Subject';
4 import { Subscription } from '../Subscription';
5 import { OuterSubscriber } from '../OuterSubscriber';
6 import { subscribeToResult } from '../util/subscribeToResult';
7 export function windowToggle(openings, closingSelector) {
8 return function (source) { return source.lift(new WindowToggleOperator(openings, closingSelector)); };
10 var WindowToggleOperator = /*@__PURE__*/ (function () {
11 function WindowToggleOperator(openings, closingSelector) {
12 this.openings = openings;
13 this.closingSelector = closingSelector;
15 WindowToggleOperator.prototype.call = function (subscriber, source) {
16 return source.subscribe(new WindowToggleSubscriber(subscriber, this.openings, this.closingSelector));
18 return WindowToggleOperator;
20 var WindowToggleSubscriber = /*@__PURE__*/ (function (_super) {
21 tslib_1.__extends(WindowToggleSubscriber, _super);
22 function WindowToggleSubscriber(destination, openings, closingSelector) {
23 var _this = _super.call(this, destination) || this;
24 _this.openings = openings;
25 _this.closingSelector = closingSelector;
27 _this.add(_this.openSubscription = subscribeToResult(_this, openings, openings));
30 WindowToggleSubscriber.prototype._next = function (value) {
31 var contexts = this.contexts;
33 var len = contexts.length;
34 for (var i = 0; i < len; i++) {
35 contexts[i].window.next(value);
39 WindowToggleSubscriber.prototype._error = function (err) {
40 var contexts = this.contexts;
43 var len = contexts.length;
45 while (++index < len) {
46 var context_1 = contexts[index];
47 context_1.window.error(err);
48 context_1.subscription.unsubscribe();
51 _super.prototype._error.call(this, err);
53 WindowToggleSubscriber.prototype._complete = function () {
54 var contexts = this.contexts;
57 var len = contexts.length;
59 while (++index < len) {
60 var context_2 = contexts[index];
61 context_2.window.complete();
62 context_2.subscription.unsubscribe();
65 _super.prototype._complete.call(this);
67 WindowToggleSubscriber.prototype._unsubscribe = function () {
68 var contexts = this.contexts;
71 var len = contexts.length;
73 while (++index < len) {
74 var context_3 = contexts[index];
75 context_3.window.unsubscribe();
76 context_3.subscription.unsubscribe();
80 WindowToggleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
81 if (outerValue === this.openings) {
82 var closingNotifier = void 0;
84 var closingSelector = this.closingSelector;
85 closingNotifier = closingSelector(innerValue);
90 var window_1 = new Subject();
91 var subscription = new Subscription();
92 var context_4 = { window: window_1, subscription: subscription };
93 this.contexts.push(context_4);
94 var innerSubscription = subscribeToResult(this, closingNotifier, context_4);
95 if (innerSubscription.closed) {
96 this.closeWindow(this.contexts.length - 1);
99 innerSubscription.context = context_4;
100 subscription.add(innerSubscription);
102 this.destination.next(window_1);
105 this.closeWindow(this.contexts.indexOf(outerValue));
108 WindowToggleSubscriber.prototype.notifyError = function (err) {
111 WindowToggleSubscriber.prototype.notifyComplete = function (inner) {
112 if (inner !== this.openSubscription) {
113 this.closeWindow(this.contexts.indexOf(inner.context));
116 WindowToggleSubscriber.prototype.closeWindow = function (index) {
120 var contexts = this.contexts;
121 var context = contexts[index];
122 var window = context.window, subscription = context.subscription;
123 contexts.splice(index, 1);
125 subscription.unsubscribe();
127 return WindowToggleSubscriber;
129 //# sourceMappingURL=windowToggle.js.map