Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

window.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { Subject } from '../Subject';
  2. import { SimpleOuterSubscriber, innerSubscribe, SimpleInnerSubscriber } from '../innerSubscribe';
  3. export function window(windowBoundaries) {
  4. return function windowOperatorFunction(source) {
  5. return source.lift(new WindowOperator(windowBoundaries));
  6. };
  7. }
  8. class WindowOperator {
  9. constructor(windowBoundaries) {
  10. this.windowBoundaries = windowBoundaries;
  11. }
  12. call(subscriber, source) {
  13. const windowSubscriber = new WindowSubscriber(subscriber);
  14. const sourceSubscription = source.subscribe(windowSubscriber);
  15. if (!sourceSubscription.closed) {
  16. windowSubscriber.add(innerSubscribe(this.windowBoundaries, new SimpleInnerSubscriber(windowSubscriber)));
  17. }
  18. return sourceSubscription;
  19. }
  20. }
  21. class WindowSubscriber extends SimpleOuterSubscriber {
  22. constructor(destination) {
  23. super(destination);
  24. this.window = new Subject();
  25. destination.next(this.window);
  26. }
  27. notifyNext() {
  28. this.openWindow();
  29. }
  30. notifyError(error) {
  31. this._error(error);
  32. }
  33. notifyComplete() {
  34. this._complete();
  35. }
  36. _next(value) {
  37. this.window.next(value);
  38. }
  39. _error(err) {
  40. this.window.error(err);
  41. this.destination.error(err);
  42. }
  43. _complete() {
  44. this.window.complete();
  45. this.destination.complete();
  46. }
  47. _unsubscribe() {
  48. this.window = null;
  49. }
  50. openWindow() {
  51. const prevWindow = this.window;
  52. if (prevWindow) {
  53. prevWindow.complete();
  54. }
  55. const destination = this.destination;
  56. const newWindow = this.window = new Subject();
  57. destination.next(newWindow);
  58. }
  59. }
  60. //# sourceMappingURL=window.js.map