windowWhen.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { Subject } from '../Subject';
  2. import { operate } from '../util/lift';
  3. import { createOperatorSubscriber } from './OperatorSubscriber';
  4. import { innerFrom } from '../observable/innerFrom';
  5. export function windowWhen(closingSelector) {
  6. return operate((source, subscriber) => {
  7. let window;
  8. let closingSubscriber;
  9. const handleError = (err) => {
  10. window.error(err);
  11. subscriber.error(err);
  12. };
  13. const openWindow = () => {
  14. closingSubscriber === null || closingSubscriber === void 0 ? void 0 : closingSubscriber.unsubscribe();
  15. window === null || window === void 0 ? void 0 : window.complete();
  16. window = new Subject();
  17. subscriber.next(window.asObservable());
  18. let closingNotifier;
  19. try {
  20. closingNotifier = innerFrom(closingSelector());
  21. }
  22. catch (err) {
  23. handleError(err);
  24. return;
  25. }
  26. closingNotifier.subscribe((closingSubscriber = createOperatorSubscriber(subscriber, openWindow, openWindow, handleError)));
  27. };
  28. openWindow();
  29. source.subscribe(createOperatorSubscriber(subscriber, (value) => window.next(value), () => {
  30. window.complete();
  31. subscriber.complete();
  32. }, handleError, () => {
  33. closingSubscriber === null || closingSubscriber === void 0 ? void 0 : closingSubscriber.unsubscribe();
  34. window = null;
  35. }));
  36. });
  37. }
  38. //# sourceMappingURL=windowWhen.js.map