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.9KB

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