1 /** PURE_IMPORTS_START tslib,_Subject,_OuterSubscriber,_util_subscribeToResult PURE_IMPORTS_END */
2 import * as tslib_1 from "tslib";
3 import { Subject } from '../Subject';
4 import { OuterSubscriber } from '../OuterSubscriber';
5 import { subscribeToResult } from '../util/subscribeToResult';
6 export function windowWhen(closingSelector) {
7 return function windowWhenOperatorFunction(source) {
8 return source.lift(new WindowOperator(closingSelector));
11 var WindowOperator = /*@__PURE__*/ (function () {
12 function WindowOperator(closingSelector) {
13 this.closingSelector = closingSelector;
15 WindowOperator.prototype.call = function (subscriber, source) {
16 return source.subscribe(new WindowSubscriber(subscriber, this.closingSelector));
18 return WindowOperator;
20 var WindowSubscriber = /*@__PURE__*/ (function (_super) {
21 tslib_1.__extends(WindowSubscriber, _super);
22 function WindowSubscriber(destination, closingSelector) {
23 var _this = _super.call(this, destination) || this;
24 _this.destination = destination;
25 _this.closingSelector = closingSelector;
29 WindowSubscriber.prototype.notifyNext = function (_outerValue, _innerValue, _outerIndex, _innerIndex, innerSub) {
30 this.openWindow(innerSub);
32 WindowSubscriber.prototype.notifyError = function (error) {
35 WindowSubscriber.prototype.notifyComplete = function (innerSub) {
36 this.openWindow(innerSub);
38 WindowSubscriber.prototype._next = function (value) {
39 this.window.next(value);
41 WindowSubscriber.prototype._error = function (err) {
42 this.window.error(err);
43 this.destination.error(err);
44 this.unsubscribeClosingNotification();
46 WindowSubscriber.prototype._complete = function () {
47 this.window.complete();
48 this.destination.complete();
49 this.unsubscribeClosingNotification();
51 WindowSubscriber.prototype.unsubscribeClosingNotification = function () {
52 if (this.closingNotification) {
53 this.closingNotification.unsubscribe();
56 WindowSubscriber.prototype.openWindow = function (innerSub) {
57 if (innerSub === void 0) {
61 this.remove(innerSub);
62 innerSub.unsubscribe();
64 var prevWindow = this.window;
66 prevWindow.complete();
68 var window = this.window = new Subject();
69 this.destination.next(window);
72 var closingSelector = this.closingSelector;
73 closingNotifier = closingSelector();
76 this.destination.error(e);
80 this.add(this.closingNotification = subscribeToResult(this, closingNotifier));
82 return WindowSubscriber;
84 //# sourceMappingURL=windowWhen.js.map