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.

bufferWhen.js 3.6KB

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