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 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { Subject } from '../Subject';
  2. import { OuterSubscriber } from '../OuterSubscriber';
  3. import { subscribeToResult } from '../util/subscribeToResult';
  4. export function repeatWhen(notifier) {
  5. return (source) => source.lift(new RepeatWhenOperator(notifier));
  6. }
  7. class RepeatWhenOperator {
  8. constructor(notifier) {
  9. this.notifier = notifier;
  10. }
  11. call(subscriber, source) {
  12. return source.subscribe(new RepeatWhenSubscriber(subscriber, this.notifier, source));
  13. }
  14. }
  15. class RepeatWhenSubscriber extends OuterSubscriber {
  16. constructor(destination, notifier, source) {
  17. super(destination);
  18. this.notifier = notifier;
  19. this.source = source;
  20. this.sourceIsBeingSubscribedTo = true;
  21. }
  22. notifyNext(outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  23. this.sourceIsBeingSubscribedTo = true;
  24. this.source.subscribe(this);
  25. }
  26. notifyComplete(innerSub) {
  27. if (this.sourceIsBeingSubscribedTo === false) {
  28. return super.complete();
  29. }
  30. }
  31. complete() {
  32. this.sourceIsBeingSubscribedTo = false;
  33. if (!this.isStopped) {
  34. if (!this.retries) {
  35. this.subscribeToRetries();
  36. }
  37. if (!this.retriesSubscription || this.retriesSubscription.closed) {
  38. return super.complete();
  39. }
  40. this._unsubscribeAndRecycle();
  41. this.notifications.next();
  42. }
  43. }
  44. _unsubscribe() {
  45. const { notifications, retriesSubscription } = this;
  46. if (notifications) {
  47. notifications.unsubscribe();
  48. this.notifications = null;
  49. }
  50. if (retriesSubscription) {
  51. retriesSubscription.unsubscribe();
  52. this.retriesSubscription = null;
  53. }
  54. this.retries = null;
  55. }
  56. _unsubscribeAndRecycle() {
  57. const { _unsubscribe } = this;
  58. this._unsubscribe = null;
  59. super._unsubscribeAndRecycle();
  60. this._unsubscribe = _unsubscribe;
  61. return this;
  62. }
  63. subscribeToRetries() {
  64. this.notifications = new Subject();
  65. let retries;
  66. try {
  67. const { notifier } = this;
  68. retries = notifier(this.notifications);
  69. }
  70. catch (e) {
  71. return super.complete();
  72. }
  73. this.retries = retries;
  74. this.retriesSubscription = subscribeToResult(this, retries);
  75. }
  76. }
  77. //# sourceMappingURL=repeatWhen.js.map