rxjs
Version:
Reactive Extensions for modern JavaScript
38 lines • 1.6 kB
JavaScript
import { Subject } from '../Subject';
import { operate } from '../util/lift';
import { OperatorSubscriber } from './OperatorSubscriber';
import { innerFrom } from '../observable/innerFrom';
export function windowWhen(closingSelector) {
return operate(function (source, subscriber) {
var window;
var closingSubscriber;
var handleError = function (err) {
window.error(err);
subscriber.error(err);
};
var openWindow = function () {
closingSubscriber === null || closingSubscriber === void 0 ? void 0 : closingSubscriber.unsubscribe();
window === null || window === void 0 ? void 0 : window.complete();
window = new Subject();
subscriber.next(window.asObservable());
var closingNotifier;
try {
closingNotifier = innerFrom(closingSelector());
}
catch (err) {
handleError(err);
return;
}
closingNotifier.subscribe((closingSubscriber = new OperatorSubscriber(subscriber, openWindow, openWindow, handleError)));
};
openWindow();
source.subscribe(new OperatorSubscriber(subscriber, function (value) { return window.next(value); }, function () {
window.complete();
subscriber.complete();
}, handleError, function () {
closingSubscriber === null || closingSubscriber === void 0 ? void 0 : closingSubscriber.unsubscribe();
window = null;
}));
});
}
//# sourceMappingURL=windowWhen.js.map