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);
9 return function (d, b) {
11 function __() { this.constructor = d; }
12 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
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)); };
23 exports.windowToggle = windowToggle;
24 var WindowToggleOperator = (function () {
25 function WindowToggleOperator(openings, closingSelector) {
26 this.openings = openings;
27 this.closingSelector = closingSelector;
29 WindowToggleOperator.prototype.call = function (subscriber, source) {
30 return source.subscribe(new WindowToggleSubscriber(subscriber, this.openings, this.closingSelector));
32 return WindowToggleOperator;
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;
41 _this.add(_this.openSubscription = subscribeToResult_1.subscribeToResult(_this, openings, openings));
44 WindowToggleSubscriber.prototype._next = function (value) {
45 var contexts = this.contexts;
47 var len = contexts.length;
48 for (var i = 0; i < len; i++) {
49 contexts[i].window.next(value);
53 WindowToggleSubscriber.prototype._error = function (err) {
54 var contexts = this.contexts;
57 var len = contexts.length;
59 while (++index < len) {
60 var context_1 = contexts[index];
61 context_1.window.error(err);
62 context_1.subscription.unsubscribe();
65 _super.prototype._error.call(this, err);
67 WindowToggleSubscriber.prototype._complete = function () {
68 var contexts = this.contexts;
71 var len = contexts.length;
73 while (++index < len) {
74 var context_2 = contexts[index];
75 context_2.window.complete();
76 context_2.subscription.unsubscribe();
79 _super.prototype._complete.call(this);
81 WindowToggleSubscriber.prototype._unsubscribe = function () {
82 var contexts = this.contexts;
85 var len = contexts.length;
87 while (++index < len) {
88 var context_3 = contexts[index];
89 context_3.window.unsubscribe();
90 context_3.subscription.unsubscribe();
94 WindowToggleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
95 if (outerValue === this.openings) {
96 var closingNotifier = void 0;
98 var closingSelector = this.closingSelector;
99 closingNotifier = closingSelector(innerValue);
102 return this.error(e);
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);
113 innerSubscription.context = context_4;
114 subscription.add(innerSubscription);
116 this.destination.next(window_1);
119 this.closeWindow(this.contexts.indexOf(outerValue));
122 WindowToggleSubscriber.prototype.notifyError = function (err) {
125 WindowToggleSubscriber.prototype.notifyComplete = function (inner) {
126 if (inner !== this.openSubscription) {
127 this.closeWindow(this.contexts.indexOf(inner.context));
130 WindowToggleSubscriber.prototype.closeWindow = function (index) {
134 var contexts = this.contexts;
135 var context = contexts[index];
136 var window = context.window, subscription = context.subscription;
137 contexts.splice(index, 1);
139 subscription.unsubscribe();
141 return WindowToggleSubscriber;
142 }(OuterSubscriber_1.OuterSubscriber));
143 //# sourceMappingURL=windowToggle.js.map