windowWhen.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.windowWhen = void 0;
  4. var Subject_1 = require("../Subject");
  5. var lift_1 = require("../util/lift");
  6. var OperatorSubscriber_1 = require("./OperatorSubscriber");
  7. var innerFrom_1 = require("../observable/innerFrom");
  8. function windowWhen(closingSelector) {
  9. return lift_1.operate(function (source, subscriber) {
  10. var window;
  11. var closingSubscriber;
  12. var handleError = function (err) {
  13. window.error(err);
  14. subscriber.error(err);
  15. };
  16. var openWindow = function () {
  17. closingSubscriber === null || closingSubscriber === void 0 ? void 0 : closingSubscriber.unsubscribe();
  18. window === null || window === void 0 ? void 0 : window.complete();
  19. window = new Subject_1.Subject();
  20. subscriber.next(window.asObservable());
  21. var closingNotifier;
  22. try {
  23. closingNotifier = innerFrom_1.innerFrom(closingSelector());
  24. }
  25. catch (err) {
  26. handleError(err);
  27. return;
  28. }
  29. closingNotifier.subscribe((closingSubscriber = OperatorSubscriber_1.createOperatorSubscriber(subscriber, openWindow, openWindow, handleError)));
  30. };
  31. openWindow();
  32. source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function (value) { return window.next(value); }, function () {
  33. window.complete();
  34. subscriber.complete();
  35. }, handleError, function () {
  36. closingSubscriber === null || closingSubscriber === void 0 ? void 0 : closingSubscriber.unsubscribe();
  37. window = null;
  38. }));
  39. });
  40. }
  41. exports.windowWhen = windowWhen;
  42. //# sourceMappingURL=windowWhen.js.map