a zip code crypto-currency system good for red ONLY

repeatWhen.js 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /** PURE_IMPORTS_START .._Subject,.._util_tryCatch,.._util_errorObject,.._OuterSubscriber,.._util_subscribeToResult PURE_IMPORTS_END */
  2. var __extends = (this && this.__extends) || function (d, b) {
  3. for (var p in b)
  4. if (b.hasOwnProperty(p))
  5. d[p] = b[p];
  6. function __() { this.constructor = d; }
  7. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  8. };
  9. import { Subject } from '../Subject';
  10. import { tryCatch } from '../util/tryCatch';
  11. import { errorObject } from '../util/errorObject';
  12. import { OuterSubscriber } from '../OuterSubscriber';
  13. import { subscribeToResult } from '../util/subscribeToResult';
  14. /**
  15. * Returns an Observable that mirrors the source Observable with the exception of a `complete`. If the source
  16. * Observable calls `complete`, this method will emit to the Observable returned from `notifier`. If that Observable
  17. * calls `complete` or `error`, then this method will call `complete` or `error` on the child subscription. Otherwise
  18. * this method will resubscribe to the source Observable.
  19. *
  20. * <img src="./img/repeatWhen.png" width="100%">
  21. *
  22. * @param {function(notifications: Observable): Observable} notifier - Receives an Observable of notifications with
  23. * which a user can `complete` or `error`, aborting the repetition.
  24. * @return {Observable} The source Observable modified with repeat logic.
  25. * @method repeatWhen
  26. * @owner Observable
  27. */
  28. export function repeatWhen(notifier) {
  29. return function (source) { return source.lift(new RepeatWhenOperator(notifier)); };
  30. }
  31. var RepeatWhenOperator = /*@__PURE__*/ (/*@__PURE__*/ function () {
  32. function RepeatWhenOperator(notifier) {
  33. this.notifier = notifier;
  34. }
  35. RepeatWhenOperator.prototype.call = function (subscriber, source) {
  36. return source.subscribe(new RepeatWhenSubscriber(subscriber, this.notifier, source));
  37. };
  38. return RepeatWhenOperator;
  39. }());
  40. /**
  41. * We need this JSDoc comment for affecting ESDoc.
  42. * @ignore
  43. * @extends {Ignored}
  44. */
  45. var RepeatWhenSubscriber = /*@__PURE__*/ (/*@__PURE__*/ function (_super) {
  46. __extends(RepeatWhenSubscriber, _super);
  47. function RepeatWhenSubscriber(destination, notifier, source) {
  48. _super.call(this, destination);
  49. this.notifier = notifier;
  50. this.source = source;
  51. this.sourceIsBeingSubscribedTo = true;
  52. }
  53. RepeatWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  54. this.sourceIsBeingSubscribedTo = true;
  55. this.source.subscribe(this);
  56. };
  57. RepeatWhenSubscriber.prototype.notifyComplete = function (innerSub) {
  58. if (this.sourceIsBeingSubscribedTo === false) {
  59. return _super.prototype.complete.call(this);
  60. }
  61. };
  62. RepeatWhenSubscriber.prototype.complete = function () {
  63. this.sourceIsBeingSubscribedTo = false;
  64. if (!this.isStopped) {
  65. if (!this.retries) {
  66. this.subscribeToRetries();
  67. }
  68. if (!this.retriesSubscription || this.retriesSubscription.closed) {
  69. return _super.prototype.complete.call(this);
  70. }
  71. this._unsubscribeAndRecycle();
  72. this.notifications.next();
  73. }
  74. };
  75. /** @deprecated internal use only */ RepeatWhenSubscriber.prototype._unsubscribe = function () {
  76. var _a = this, notifications = _a.notifications, retriesSubscription = _a.retriesSubscription;
  77. if (notifications) {
  78. notifications.unsubscribe();
  79. this.notifications = null;
  80. }
  81. if (retriesSubscription) {
  82. retriesSubscription.unsubscribe();
  83. this.retriesSubscription = null;
  84. }
  85. this.retries = null;
  86. };
  87. /** @deprecated internal use only */ RepeatWhenSubscriber.prototype._unsubscribeAndRecycle = function () {
  88. var _a = this, notifications = _a.notifications, retries = _a.retries, retriesSubscription = _a.retriesSubscription;
  89. this.notifications = null;
  90. this.retries = null;
  91. this.retriesSubscription = null;
  92. _super.prototype._unsubscribeAndRecycle.call(this);
  93. this.notifications = notifications;
  94. this.retries = retries;
  95. this.retriesSubscription = retriesSubscription;
  96. return this;
  97. };
  98. RepeatWhenSubscriber.prototype.subscribeToRetries = function () {
  99. this.notifications = new Subject();
  100. var retries = tryCatch(this.notifier)(this.notifications);
  101. if (retries === errorObject) {
  102. return _super.prototype.complete.call(this);
  103. }
  104. this.retries = retries;
  105. this.retriesSubscription = subscribeToResult(this, retries);
  106. };
  107. return RepeatWhenSubscriber;
  108. }(OuterSubscriber));
  109. //# sourceMappingURL=repeatWhen.js.map