windowWhen.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /** PURE_IMPORTS_START tslib,_Subject,_OuterSubscriber,_util_subscribeToResult PURE_IMPORTS_END */
  2. import * as tslib_1 from "tslib";
  3. import { Subject } from '../Subject';
  4. import { OuterSubscriber } from '../OuterSubscriber';
  5. import { subscribeToResult } from '../util/subscribeToResult';
  6. export function windowWhen(closingSelector) {
  7. return function windowWhenOperatorFunction(source) {
  8. return source.lift(new WindowOperator(closingSelector));
  9. };
  10. }
  11. var WindowOperator = /*@__PURE__*/ (function () {
  12. function WindowOperator(closingSelector) {
  13. this.closingSelector = closingSelector;
  14. }
  15. WindowOperator.prototype.call = function (subscriber, source) {
  16. return source.subscribe(new WindowSubscriber(subscriber, this.closingSelector));
  17. };
  18. return WindowOperator;
  19. }());
  20. var WindowSubscriber = /*@__PURE__*/ (function (_super) {
  21. tslib_1.__extends(WindowSubscriber, _super);
  22. function WindowSubscriber(destination, closingSelector) {
  23. var _this = _super.call(this, destination) || this;
  24. _this.destination = destination;
  25. _this.closingSelector = closingSelector;
  26. _this.openWindow();
  27. return _this;
  28. }
  29. WindowSubscriber.prototype.notifyNext = function (_outerValue, _innerValue, _outerIndex, _innerIndex, innerSub) {
  30. this.openWindow(innerSub);
  31. };
  32. WindowSubscriber.prototype.notifyError = function (error) {
  33. this._error(error);
  34. };
  35. WindowSubscriber.prototype.notifyComplete = function (innerSub) {
  36. this.openWindow(innerSub);
  37. };
  38. WindowSubscriber.prototype._next = function (value) {
  39. this.window.next(value);
  40. };
  41. WindowSubscriber.prototype._error = function (err) {
  42. this.window.error(err);
  43. this.destination.error(err);
  44. this.unsubscribeClosingNotification();
  45. };
  46. WindowSubscriber.prototype._complete = function () {
  47. this.window.complete();
  48. this.destination.complete();
  49. this.unsubscribeClosingNotification();
  50. };
  51. WindowSubscriber.prototype.unsubscribeClosingNotification = function () {
  52. if (this.closingNotification) {
  53. this.closingNotification.unsubscribe();
  54. }
  55. };
  56. WindowSubscriber.prototype.openWindow = function (innerSub) {
  57. if (innerSub === void 0) {
  58. innerSub = null;
  59. }
  60. if (innerSub) {
  61. this.remove(innerSub);
  62. innerSub.unsubscribe();
  63. }
  64. var prevWindow = this.window;
  65. if (prevWindow) {
  66. prevWindow.complete();
  67. }
  68. var window = this.window = new Subject();
  69. this.destination.next(window);
  70. var closingNotifier;
  71. try {
  72. var closingSelector = this.closingSelector;
  73. closingNotifier = closingSelector();
  74. }
  75. catch (e) {
  76. this.destination.error(e);
  77. this.window.error(e);
  78. return;
  79. }
  80. this.add(this.closingNotification = subscribeToResult(this, closingNotifier));
  81. };
  82. return WindowSubscriber;
  83. }(OuterSubscriber));
  84. //# sourceMappingURL=windowWhen.js.map