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

windowWhen.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { Subject } from '../Subject';
  2. import { OuterSubscriber } from '../OuterSubscriber';
  3. import { subscribeToResult } from '../util/subscribeToResult';
  4. export function windowWhen(closingSelector) {
  5. return function windowWhenOperatorFunction(source) {
  6. return source.lift(new WindowOperator(closingSelector));
  7. };
  8. }
  9. class WindowOperator {
  10. constructor(closingSelector) {
  11. this.closingSelector = closingSelector;
  12. }
  13. call(subscriber, source) {
  14. return source.subscribe(new WindowSubscriber(subscriber, this.closingSelector));
  15. }
  16. }
  17. class WindowSubscriber extends OuterSubscriber {
  18. constructor(destination, closingSelector) {
  19. super(destination);
  20. this.destination = destination;
  21. this.closingSelector = closingSelector;
  22. this.openWindow();
  23. }
  24. notifyNext(_outerValue, _innerValue, _outerIndex, _innerIndex, innerSub) {
  25. this.openWindow(innerSub);
  26. }
  27. notifyError(error) {
  28. this._error(error);
  29. }
  30. notifyComplete(innerSub) {
  31. this.openWindow(innerSub);
  32. }
  33. _next(value) {
  34. this.window.next(value);
  35. }
  36. _error(err) {
  37. this.window.error(err);
  38. this.destination.error(err);
  39. this.unsubscribeClosingNotification();
  40. }
  41. _complete() {
  42. this.window.complete();
  43. this.destination.complete();
  44. this.unsubscribeClosingNotification();
  45. }
  46. unsubscribeClosingNotification() {
  47. if (this.closingNotification) {
  48. this.closingNotification.unsubscribe();
  49. }
  50. }
  51. openWindow(innerSub = null) {
  52. if (innerSub) {
  53. this.remove(innerSub);
  54. innerSub.unsubscribe();
  55. }
  56. const prevWindow = this.window;
  57. if (prevWindow) {
  58. prevWindow.complete();
  59. }
  60. const window = this.window = new Subject();
  61. this.destination.next(window);
  62. let closingNotifier;
  63. try {
  64. const { closingSelector } = this;
  65. closingNotifier = closingSelector();
  66. }
  67. catch (e) {
  68. this.destination.error(e);
  69. this.window.error(e);
  70. return;
  71. }
  72. this.add(this.closingNotification = subscribeToResult(this, closingNotifier));
  73. }
  74. }
  75. //# sourceMappingURL=windowWhen.js.map