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.

windowToggle.js 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 Subscription_1 = require("../Subscription");
  18. var tryCatch_1 = require("../util/tryCatch");
  19. var errorObject_1 = require("../util/errorObject");
  20. var OuterSubscriber_1 = require("../OuterSubscriber");
  21. var subscribeToResult_1 = require("../util/subscribeToResult");
  22. function windowToggle(openings, closingSelector) {
  23. return function (source) { return source.lift(new WindowToggleOperator(openings, closingSelector)); };
  24. }
  25. exports.windowToggle = windowToggle;
  26. var WindowToggleOperator = (function () {
  27. function WindowToggleOperator(openings, closingSelector) {
  28. this.openings = openings;
  29. this.closingSelector = closingSelector;
  30. }
  31. WindowToggleOperator.prototype.call = function (subscriber, source) {
  32. return source.subscribe(new WindowToggleSubscriber(subscriber, this.openings, this.closingSelector));
  33. };
  34. return WindowToggleOperator;
  35. }());
  36. var WindowToggleSubscriber = (function (_super) {
  37. __extends(WindowToggleSubscriber, _super);
  38. function WindowToggleSubscriber(destination, openings, closingSelector) {
  39. var _this = _super.call(this, destination) || this;
  40. _this.openings = openings;
  41. _this.closingSelector = closingSelector;
  42. _this.contexts = [];
  43. _this.add(_this.openSubscription = subscribeToResult_1.subscribeToResult(_this, openings, openings));
  44. return _this;
  45. }
  46. WindowToggleSubscriber.prototype._next = function (value) {
  47. var contexts = this.contexts;
  48. if (contexts) {
  49. var len = contexts.length;
  50. for (var i = 0; i < len; i++) {
  51. contexts[i].window.next(value);
  52. }
  53. }
  54. };
  55. WindowToggleSubscriber.prototype._error = function (err) {
  56. var contexts = this.contexts;
  57. this.contexts = null;
  58. if (contexts) {
  59. var len = contexts.length;
  60. var index = -1;
  61. while (++index < len) {
  62. var context_1 = contexts[index];
  63. context_1.window.error(err);
  64. context_1.subscription.unsubscribe();
  65. }
  66. }
  67. _super.prototype._error.call(this, err);
  68. };
  69. WindowToggleSubscriber.prototype._complete = function () {
  70. var contexts = this.contexts;
  71. this.contexts = null;
  72. if (contexts) {
  73. var len = contexts.length;
  74. var index = -1;
  75. while (++index < len) {
  76. var context_2 = contexts[index];
  77. context_2.window.complete();
  78. context_2.subscription.unsubscribe();
  79. }
  80. }
  81. _super.prototype._complete.call(this);
  82. };
  83. WindowToggleSubscriber.prototype._unsubscribe = function () {
  84. var contexts = this.contexts;
  85. this.contexts = null;
  86. if (contexts) {
  87. var len = contexts.length;
  88. var index = -1;
  89. while (++index < len) {
  90. var context_3 = contexts[index];
  91. context_3.window.unsubscribe();
  92. context_3.subscription.unsubscribe();
  93. }
  94. }
  95. };
  96. WindowToggleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  97. if (outerValue === this.openings) {
  98. var closingSelector = this.closingSelector;
  99. var closingNotifier = tryCatch_1.tryCatch(closingSelector)(innerValue);
  100. if (closingNotifier === errorObject_1.errorObject) {
  101. return this.error(errorObject_1.errorObject.e);
  102. }
  103. else {
  104. var window_1 = new Subject_1.Subject();
  105. var subscription = new Subscription_1.Subscription();
  106. var context_4 = { window: window_1, subscription: subscription };
  107. this.contexts.push(context_4);
  108. var innerSubscription = subscribeToResult_1.subscribeToResult(this, closingNotifier, context_4);
  109. if (innerSubscription.closed) {
  110. this.closeWindow(this.contexts.length - 1);
  111. }
  112. else {
  113. innerSubscription.context = context_4;
  114. subscription.add(innerSubscription);
  115. }
  116. this.destination.next(window_1);
  117. }
  118. }
  119. else {
  120. this.closeWindow(this.contexts.indexOf(outerValue));
  121. }
  122. };
  123. WindowToggleSubscriber.prototype.notifyError = function (err) {
  124. this.error(err);
  125. };
  126. WindowToggleSubscriber.prototype.notifyComplete = function (inner) {
  127. if (inner !== this.openSubscription) {
  128. this.closeWindow(this.contexts.indexOf(inner.context));
  129. }
  130. };
  131. WindowToggleSubscriber.prototype.closeWindow = function (index) {
  132. if (index === -1) {
  133. return;
  134. }
  135. var contexts = this.contexts;
  136. var context = contexts[index];
  137. var window = context.window, subscription = context.subscription;
  138. contexts.splice(index, 1);
  139. window.complete();
  140. subscription.unsubscribe();
  141. };
  142. return WindowToggleSubscriber;
  143. }(OuterSubscriber_1.OuterSubscriber));
  144. //# sourceMappingURL=windowToggle.js.map