Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repeatWhen.js 3.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 OuterSubscriber_1 = require("../OuterSubscriber");
  18. var subscribeToResult_1 = require("../util/subscribeToResult");
  19. function repeatWhen(notifier) {
  20. return function (source) { return source.lift(new RepeatWhenOperator(notifier)); };
  21. }
  22. exports.repeatWhen = repeatWhen;
  23. var RepeatWhenOperator = (function () {
  24. function RepeatWhenOperator(notifier) {
  25. this.notifier = notifier;
  26. }
  27. RepeatWhenOperator.prototype.call = function (subscriber, source) {
  28. return source.subscribe(new RepeatWhenSubscriber(subscriber, this.notifier, source));
  29. };
  30. return RepeatWhenOperator;
  31. }());
  32. var RepeatWhenSubscriber = (function (_super) {
  33. __extends(RepeatWhenSubscriber, _super);
  34. function RepeatWhenSubscriber(destination, notifier, source) {
  35. var _this = _super.call(this, destination) || this;
  36. _this.notifier = notifier;
  37. _this.source = source;
  38. _this.sourceIsBeingSubscribedTo = true;
  39. return _this;
  40. }
  41. RepeatWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  42. this.sourceIsBeingSubscribedTo = true;
  43. this.source.subscribe(this);
  44. };
  45. RepeatWhenSubscriber.prototype.notifyComplete = function (innerSub) {
  46. if (this.sourceIsBeingSubscribedTo === false) {
  47. return _super.prototype.complete.call(this);
  48. }
  49. };
  50. RepeatWhenSubscriber.prototype.complete = function () {
  51. this.sourceIsBeingSubscribedTo = false;
  52. if (!this.isStopped) {
  53. if (!this.retries) {
  54. this.subscribeToRetries();
  55. }
  56. if (!this.retriesSubscription || this.retriesSubscription.closed) {
  57. return _super.prototype.complete.call(this);
  58. }
  59. this._unsubscribeAndRecycle();
  60. this.notifications.next();
  61. }
  62. };
  63. RepeatWhenSubscriber.prototype._unsubscribe = function () {
  64. var _a = this, notifications = _a.notifications, retriesSubscription = _a.retriesSubscription;
  65. if (notifications) {
  66. notifications.unsubscribe();
  67. this.notifications = null;
  68. }
  69. if (retriesSubscription) {
  70. retriesSubscription.unsubscribe();
  71. this.retriesSubscription = null;
  72. }
  73. this.retries = null;
  74. };
  75. RepeatWhenSubscriber.prototype._unsubscribeAndRecycle = function () {
  76. var _unsubscribe = this._unsubscribe;
  77. this._unsubscribe = null;
  78. _super.prototype._unsubscribeAndRecycle.call(this);
  79. this._unsubscribe = _unsubscribe;
  80. return this;
  81. };
  82. RepeatWhenSubscriber.prototype.subscribeToRetries = function () {
  83. this.notifications = new Subject_1.Subject();
  84. var retries;
  85. try {
  86. var notifier = this.notifier;
  87. retries = notifier(this.notifications);
  88. }
  89. catch (e) {
  90. return _super.prototype.complete.call(this);
  91. }
  92. this.retries = retries;
  93. this.retriesSubscription = subscribeToResult_1.subscribeToResult(this, retries);
  94. };
  95. return RepeatWhenSubscriber;
  96. }(OuterSubscriber_1.OuterSubscriber));
  97. //# sourceMappingURL=repeatWhen.js.map