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 OuterSubscriber_1 = require("../OuterSubscriber");
18 var subscribeToResult_1 = require("../util/subscribeToResult");
19 function windowWhen(closingSelector) {
20 return function windowWhenOperatorFunction(source) {
21 return source.lift(new WindowOperator(closingSelector));
24 exports.windowWhen = windowWhen;
25 var WindowOperator = (function () {
26 function WindowOperator(closingSelector) {
27 this.closingSelector = closingSelector;
29 WindowOperator.prototype.call = function (subscriber, source) {
30 return source.subscribe(new WindowSubscriber(subscriber, this.closingSelector));
32 return WindowOperator;
34 var WindowSubscriber = (function (_super) {
35 __extends(WindowSubscriber, _super);
36 function WindowSubscriber(destination, closingSelector) {
37 var _this = _super.call(this, destination) || this;
38 _this.destination = destination;
39 _this.closingSelector = closingSelector;
43 WindowSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
44 this.openWindow(innerSub);
46 WindowSubscriber.prototype.notifyError = function (error, innerSub) {
49 WindowSubscriber.prototype.notifyComplete = function (innerSub) {
50 this.openWindow(innerSub);
52 WindowSubscriber.prototype._next = function (value) {
53 this.window.next(value);
55 WindowSubscriber.prototype._error = function (err) {
56 this.window.error(err);
57 this.destination.error(err);
58 this.unsubscribeClosingNotification();
60 WindowSubscriber.prototype._complete = function () {
61 this.window.complete();
62 this.destination.complete();
63 this.unsubscribeClosingNotification();
65 WindowSubscriber.prototype.unsubscribeClosingNotification = function () {
66 if (this.closingNotification) {
67 this.closingNotification.unsubscribe();
70 WindowSubscriber.prototype.openWindow = function (innerSub) {
71 if (innerSub === void 0) { innerSub = null; }
73 this.remove(innerSub);
74 innerSub.unsubscribe();
76 var prevWindow = this.window;
78 prevWindow.complete();
80 var window = this.window = new Subject_1.Subject();
81 this.destination.next(window);
84 var closingSelector = this.closingSelector;
85 closingNotifier = closingSelector();
88 this.destination.error(e);
92 this.add(this.closingNotification = subscribeToResult_1.subscribeToResult(this, closingNotifier));
94 return WindowSubscriber;
95 }(OuterSubscriber_1.OuterSubscriber));
96 //# sourceMappingURL=windowWhen.js.map