repeatWhen.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /** PURE_IMPORTS_START tslib,_Subject,_innerSubscribe PURE_IMPORTS_END */
  2. import * as tslib_1 from "tslib";
  3. import { Subject } from '../Subject';
  4. import { SimpleOuterSubscriber, innerSubscribe, SimpleInnerSubscriber } from '../innerSubscribe';
  5. export function repeatWhen(notifier) {
  6. return function (source) { return source.lift(new RepeatWhenOperator(notifier)); };
  7. }
  8. var RepeatWhenOperator = /*@__PURE__*/ (function () {
  9. function RepeatWhenOperator(notifier) {
  10. this.notifier = notifier;
  11. }
  12. RepeatWhenOperator.prototype.call = function (subscriber, source) {
  13. return source.subscribe(new RepeatWhenSubscriber(subscriber, this.notifier, source));
  14. };
  15. return RepeatWhenOperator;
  16. }());
  17. var RepeatWhenSubscriber = /*@__PURE__*/ (function (_super) {
  18. tslib_1.__extends(RepeatWhenSubscriber, _super);
  19. function RepeatWhenSubscriber(destination, notifier, source) {
  20. var _this = _super.call(this, destination) || this;
  21. _this.notifier = notifier;
  22. _this.source = source;
  23. _this.sourceIsBeingSubscribedTo = true;
  24. return _this;
  25. }
  26. RepeatWhenSubscriber.prototype.notifyNext = function () {
  27. this.sourceIsBeingSubscribedTo = true;
  28. this.source.subscribe(this);
  29. };
  30. RepeatWhenSubscriber.prototype.notifyComplete = function () {
  31. if (this.sourceIsBeingSubscribedTo === false) {
  32. return _super.prototype.complete.call(this);
  33. }
  34. };
  35. RepeatWhenSubscriber.prototype.complete = function () {
  36. this.sourceIsBeingSubscribedTo = false;
  37. if (!this.isStopped) {
  38. if (!this.retries) {
  39. this.subscribeToRetries();
  40. }
  41. if (!this.retriesSubscription || this.retriesSubscription.closed) {
  42. return _super.prototype.complete.call(this);
  43. }
  44. this._unsubscribeAndRecycle();
  45. this.notifications.next(undefined);
  46. }
  47. };
  48. RepeatWhenSubscriber.prototype._unsubscribe = function () {
  49. var _a = this, notifications = _a.notifications, retriesSubscription = _a.retriesSubscription;
  50. if (notifications) {
  51. notifications.unsubscribe();
  52. this.notifications = undefined;
  53. }
  54. if (retriesSubscription) {
  55. retriesSubscription.unsubscribe();
  56. this.retriesSubscription = undefined;
  57. }
  58. this.retries = undefined;
  59. };
  60. RepeatWhenSubscriber.prototype._unsubscribeAndRecycle = function () {
  61. var _unsubscribe = this._unsubscribe;
  62. this._unsubscribe = null;
  63. _super.prototype._unsubscribeAndRecycle.call(this);
  64. this._unsubscribe = _unsubscribe;
  65. return this;
  66. };
  67. RepeatWhenSubscriber.prototype.subscribeToRetries = function () {
  68. this.notifications = new Subject();
  69. var retries;
  70. try {
  71. var notifier = this.notifier;
  72. retries = notifier(this.notifications);
  73. }
  74. catch (e) {
  75. return _super.prototype.complete.call(this);
  76. }
  77. this.retries = retries;
  78. this.retriesSubscription = innerSubscribe(retries, new SimpleInnerSubscriber(this));
  79. };
  80. return RepeatWhenSubscriber;
  81. }(SimpleOuterSubscriber));
  82. //# sourceMappingURL=repeatWhen.js.map