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.

windowWhen.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 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 windowWhen(closingSelector) {
  22. return function windowWhenOperatorFunction(source) {
  23. return source.lift(new WindowOperator(closingSelector));
  24. };
  25. }
  26. exports.windowWhen = windowWhen;
  27. var WindowOperator = (function () {
  28. function WindowOperator(closingSelector) {
  29. this.closingSelector = closingSelector;
  30. }
  31. WindowOperator.prototype.call = function (subscriber, source) {
  32. return source.subscribe(new WindowSubscriber(subscriber, this.closingSelector));
  33. };
  34. return WindowOperator;
  35. }());
  36. var WindowSubscriber = (function (_super) {
  37. __extends(WindowSubscriber, _super);
  38. function WindowSubscriber(destination, closingSelector) {
  39. var _this = _super.call(this, destination) || this;
  40. _this.destination = destination;
  41. _this.closingSelector = closingSelector;
  42. _this.openWindow();
  43. return _this;
  44. }
  45. WindowSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  46. this.openWindow(innerSub);
  47. };
  48. WindowSubscriber.prototype.notifyError = function (error, innerSub) {
  49. this._error(error);
  50. };
  51. WindowSubscriber.prototype.notifyComplete = function (innerSub) {
  52. this.openWindow(innerSub);
  53. };
  54. WindowSubscriber.prototype._next = function (value) {
  55. this.window.next(value);
  56. };
  57. WindowSubscriber.prototype._error = function (err) {
  58. this.window.error(err);
  59. this.destination.error(err);
  60. this.unsubscribeClosingNotification();
  61. };
  62. WindowSubscriber.prototype._complete = function () {
  63. this.window.complete();
  64. this.destination.complete();
  65. this.unsubscribeClosingNotification();
  66. };
  67. WindowSubscriber.prototype.unsubscribeClosingNotification = function () {
  68. if (this.closingNotification) {
  69. this.closingNotification.unsubscribe();
  70. }
  71. };
  72. WindowSubscriber.prototype.openWindow = function (innerSub) {
  73. if (innerSub === void 0) { innerSub = null; }
  74. if (innerSub) {
  75. this.remove(innerSub);
  76. innerSub.unsubscribe();
  77. }
  78. var prevWindow = this.window;
  79. if (prevWindow) {
  80. prevWindow.complete();
  81. }
  82. var window = this.window = new Subject_1.Subject();
  83. this.destination.next(window);
  84. var closingNotifier = tryCatch_1.tryCatch(this.closingSelector)();
  85. if (closingNotifier === errorObject_1.errorObject) {
  86. var err = errorObject_1.errorObject.e;
  87. this.destination.error(err);
  88. this.window.error(err);
  89. }
  90. else {
  91. this.add(this.closingNotification = subscribeToResult_1.subscribeToResult(this, closingNotifier));
  92. }
  93. };
  94. return WindowSubscriber;
  95. }(OuterSubscriber_1.OuterSubscriber));
  96. //# sourceMappingURL=windowWhen.js.map