window.js 1.2 KB

12345678910111213141516171819202122232425262728
  1. import { Subject } from '../Subject';
  2. import { operate } from '../util/lift';
  3. import { createOperatorSubscriber } from './OperatorSubscriber';
  4. import { noop } from '../util/noop';
  5. import { innerFrom } from '../observable/innerFrom';
  6. export function window(windowBoundaries) {
  7. return operate((source, subscriber) => {
  8. let windowSubject = new Subject();
  9. subscriber.next(windowSubject.asObservable());
  10. const errorHandler = (err) => {
  11. windowSubject.error(err);
  12. subscriber.error(err);
  13. };
  14. source.subscribe(createOperatorSubscriber(subscriber, (value) => windowSubject === null || windowSubject === void 0 ? void 0 : windowSubject.next(value), () => {
  15. windowSubject.complete();
  16. subscriber.complete();
  17. }, errorHandler));
  18. innerFrom(windowBoundaries).subscribe(createOperatorSubscriber(subscriber, () => {
  19. windowSubject.complete();
  20. subscriber.next((windowSubject = new Subject()));
  21. }, noop, errorHandler));
  22. return () => {
  23. windowSubject === null || windowSubject === void 0 ? void 0 : windowSubject.unsubscribe();
  24. windowSubject = null;
  25. };
  26. });
  27. }
  28. //# sourceMappingURL=window.js.map