123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- /** PURE_IMPORTS_START tslib,_Subject,_Subscription,_OuterSubscriber,_util_subscribeToResult PURE_IMPORTS_END */
- import * as tslib_1 from "tslib";
- import { Subject } from '../Subject';
- import { Subscription } from '../Subscription';
- import { OuterSubscriber } from '../OuterSubscriber';
- import { subscribeToResult } from '../util/subscribeToResult';
- export function windowToggle(openings, closingSelector) {
- return function (source) { return source.lift(new WindowToggleOperator(openings, closingSelector)); };
- }
- var WindowToggleOperator = /*@__PURE__*/ (function () {
- function WindowToggleOperator(openings, closingSelector) {
- this.openings = openings;
- this.closingSelector = closingSelector;
- }
- WindowToggleOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new WindowToggleSubscriber(subscriber, this.openings, this.closingSelector));
- };
- return WindowToggleOperator;
- }());
- var WindowToggleSubscriber = /*@__PURE__*/ (function (_super) {
- tslib_1.__extends(WindowToggleSubscriber, _super);
- function WindowToggleSubscriber(destination, openings, closingSelector) {
- var _this = _super.call(this, destination) || this;
- _this.openings = openings;
- _this.closingSelector = closingSelector;
- _this.contexts = [];
- _this.add(_this.openSubscription = subscribeToResult(_this, openings, openings));
- return _this;
- }
- WindowToggleSubscriber.prototype._next = function (value) {
- var contexts = this.contexts;
- if (contexts) {
- var len = contexts.length;
- for (var i = 0; i < len; i++) {
- contexts[i].window.next(value);
- }
- }
- };
- WindowToggleSubscriber.prototype._error = function (err) {
- var contexts = this.contexts;
- this.contexts = null;
- if (contexts) {
- var len = contexts.length;
- var index = -1;
- while (++index < len) {
- var context_1 = contexts[index];
- context_1.window.error(err);
- context_1.subscription.unsubscribe();
- }
- }
- _super.prototype._error.call(this, err);
- };
- WindowToggleSubscriber.prototype._complete = function () {
- var contexts = this.contexts;
- this.contexts = null;
- if (contexts) {
- var len = contexts.length;
- var index = -1;
- while (++index < len) {
- var context_2 = contexts[index];
- context_2.window.complete();
- context_2.subscription.unsubscribe();
- }
- }
- _super.prototype._complete.call(this);
- };
- WindowToggleSubscriber.prototype._unsubscribe = function () {
- var contexts = this.contexts;
- this.contexts = null;
- if (contexts) {
- var len = contexts.length;
- var index = -1;
- while (++index < len) {
- var context_3 = contexts[index];
- context_3.window.unsubscribe();
- context_3.subscription.unsubscribe();
- }
- }
- };
- WindowToggleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
- if (outerValue === this.openings) {
- var closingNotifier = void 0;
- try {
- var closingSelector = this.closingSelector;
- closingNotifier = closingSelector(innerValue);
- }
- catch (e) {
- return this.error(e);
- }
- var window_1 = new Subject();
- var subscription = new Subscription();
- var context_4 = { window: window_1, subscription: subscription };
- this.contexts.push(context_4);
- var innerSubscription = subscribeToResult(this, closingNotifier, context_4);
- if (innerSubscription.closed) {
- this.closeWindow(this.contexts.length - 1);
- }
- else {
- innerSubscription.context = context_4;
- subscription.add(innerSubscription);
- }
- this.destination.next(window_1);
- }
- else {
- this.closeWindow(this.contexts.indexOf(outerValue));
- }
- };
- WindowToggleSubscriber.prototype.notifyError = function (err) {
- this.error(err);
- };
- WindowToggleSubscriber.prototype.notifyComplete = function (inner) {
- if (inner !== this.openSubscription) {
- this.closeWindow(this.contexts.indexOf(inner.context));
- }
- };
- WindowToggleSubscriber.prototype.closeWindow = function (index) {
- if (index === -1) {
- return;
- }
- var contexts = this.contexts;
- var context = contexts[index];
- var window = context.window, subscription = context.subscription;
- contexts.splice(index, 1);
- window.complete();
- subscription.unsubscribe();
- };
- return WindowToggleSubscriber;
- }(OuterSubscriber));
- //# sourceMappingURL=windowToggle.js.map
|