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

repeatWhen.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. }
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. var Subject_1 = require("../Subject");
  17. var innerSubscribe_1 = require("../innerSubscribe");
  18. function repeatWhen(notifier) {
  19. return function (source) { return source.lift(new RepeatWhenOperator(notifier)); };
  20. }
  21. exports.repeatWhen = repeatWhen;
  22. var RepeatWhenOperator = (function () {
  23. function RepeatWhenOperator(notifier) {
  24. this.notifier = notifier;
  25. }
  26. RepeatWhenOperator.prototype.call = function (subscriber, source) {
  27. return source.subscribe(new RepeatWhenSubscriber(subscriber, this.notifier, source));
  28. };
  29. return RepeatWhenOperator;
  30. }());
  31. var RepeatWhenSubscriber = (function (_super) {
  32. __extends(RepeatWhenSubscriber, _super);
  33. function RepeatWhenSubscriber(destination, notifier, source) {
  34. var _this = _super.call(this, destination) || this;
  35. _this.notifier = notifier;
  36. _this.source = source;
  37. _this.sourceIsBeingSubscribedTo = true;
  38. return _this;
  39. }
  40. RepeatWhenSubscriber.prototype.notifyNext = function () {
  41. this.sourceIsBeingSubscribedTo = true;
  42. this.source.subscribe(this);
  43. };
  44. RepeatWhenSubscriber.prototype.notifyComplete = function () {
  45. if (this.sourceIsBeingSubscribedTo === false) {
  46. return _super.prototype.complete.call(this);
  47. }
  48. };
  49. RepeatWhenSubscriber.prototype.complete = function () {
  50. this.sourceIsBeingSubscribedTo = false;
  51. if (!this.isStopped) {
  52. if (!this.retries) {
  53. this.subscribeToRetries();
  54. }
  55. if (!this.retriesSubscription || this.retriesSubscription.closed) {
  56. return _super.prototype.complete.call(this);
  57. }
  58. this._unsubscribeAndRecycle();
  59. this.notifications.next(undefined);
  60. }
  61. };
  62. RepeatWhenSubscriber.prototype._unsubscribe = function () {
  63. var _a = this, notifications = _a.notifications, retriesSubscription = _a.retriesSubscription;
  64. if (notifications) {
  65. notifications.unsubscribe();
  66. this.notifications = undefined;
  67. }
  68. if (retriesSubscription) {
  69. retriesSubscription.unsubscribe();
  70. this.retriesSubscription = undefined;
  71. }
  72. this.retries = undefined;
  73. };
  74. RepeatWhenSubscriber.prototype._unsubscribeAndRecycle = function () {
  75. var _unsubscribe = this._unsubscribe;
  76. this._unsubscribe = null;
  77. _super.prototype._unsubscribeAndRecycle.call(this);
  78. this._unsubscribe = _unsubscribe;
  79. return this;
  80. };
  81. RepeatWhenSubscriber.prototype.subscribeToRetries = function () {
  82. this.notifications = new Subject_1.Subject();
  83. var retries;
  84. try {
  85. var notifier = this.notifier;
  86. retries = notifier(this.notifications);
  87. }
  88. catch (e) {
  89. return _super.prototype.complete.call(this);
  90. }
  91. this.retries = retries;
  92. this.retriesSubscription = innerSubscribe_1.innerSubscribe(retries, new innerSubscribe_1.SimpleInnerSubscriber(this));
  93. };
  94. return RepeatWhenSubscriber;
  95. }(innerSubscribe_1.SimpleOuterSubscriber));
  96. //# sourceMappingURL=repeatWhen.js.map