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.

sequenceEqual.js 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 Subscriber_1 = require("../Subscriber");
  17. var tryCatch_1 = require("../util/tryCatch");
  18. var errorObject_1 = require("../util/errorObject");
  19. function sequenceEqual(compareTo, comparor) {
  20. return function (source) { return source.lift(new SequenceEqualOperator(compareTo, comparor)); };
  21. }
  22. exports.sequenceEqual = sequenceEqual;
  23. var SequenceEqualOperator = (function () {
  24. function SequenceEqualOperator(compareTo, comparor) {
  25. this.compareTo = compareTo;
  26. this.comparor = comparor;
  27. }
  28. SequenceEqualOperator.prototype.call = function (subscriber, source) {
  29. return source.subscribe(new SequenceEqualSubscriber(subscriber, this.compareTo, this.comparor));
  30. };
  31. return SequenceEqualOperator;
  32. }());
  33. exports.SequenceEqualOperator = SequenceEqualOperator;
  34. var SequenceEqualSubscriber = (function (_super) {
  35. __extends(SequenceEqualSubscriber, _super);
  36. function SequenceEqualSubscriber(destination, compareTo, comparor) {
  37. var _this = _super.call(this, destination) || this;
  38. _this.compareTo = compareTo;
  39. _this.comparor = comparor;
  40. _this._a = [];
  41. _this._b = [];
  42. _this._oneComplete = false;
  43. _this.destination.add(compareTo.subscribe(new SequenceEqualCompareToSubscriber(destination, _this)));
  44. return _this;
  45. }
  46. SequenceEqualSubscriber.prototype._next = function (value) {
  47. if (this._oneComplete && this._b.length === 0) {
  48. this.emit(false);
  49. }
  50. else {
  51. this._a.push(value);
  52. this.checkValues();
  53. }
  54. };
  55. SequenceEqualSubscriber.prototype._complete = function () {
  56. if (this._oneComplete) {
  57. this.emit(this._a.length === 0 && this._b.length === 0);
  58. }
  59. else {
  60. this._oneComplete = true;
  61. }
  62. this.unsubscribe();
  63. };
  64. SequenceEqualSubscriber.prototype.checkValues = function () {
  65. var _c = this, _a = _c._a, _b = _c._b, comparor = _c.comparor;
  66. while (_a.length > 0 && _b.length > 0) {
  67. var a = _a.shift();
  68. var b = _b.shift();
  69. var areEqual = false;
  70. if (comparor) {
  71. areEqual = tryCatch_1.tryCatch(comparor)(a, b);
  72. if (areEqual === errorObject_1.errorObject) {
  73. this.destination.error(errorObject_1.errorObject.e);
  74. }
  75. }
  76. else {
  77. areEqual = a === b;
  78. }
  79. if (!areEqual) {
  80. this.emit(false);
  81. }
  82. }
  83. };
  84. SequenceEqualSubscriber.prototype.emit = function (value) {
  85. var destination = this.destination;
  86. destination.next(value);
  87. destination.complete();
  88. };
  89. SequenceEqualSubscriber.prototype.nextB = function (value) {
  90. if (this._oneComplete && this._a.length === 0) {
  91. this.emit(false);
  92. }
  93. else {
  94. this._b.push(value);
  95. this.checkValues();
  96. }
  97. };
  98. SequenceEqualSubscriber.prototype.completeB = function () {
  99. if (this._oneComplete) {
  100. this.emit(this._a.length === 0 && this._b.length === 0);
  101. }
  102. else {
  103. this._oneComplete = true;
  104. }
  105. };
  106. return SequenceEqualSubscriber;
  107. }(Subscriber_1.Subscriber));
  108. exports.SequenceEqualSubscriber = SequenceEqualSubscriber;
  109. var SequenceEqualCompareToSubscriber = (function (_super) {
  110. __extends(SequenceEqualCompareToSubscriber, _super);
  111. function SequenceEqualCompareToSubscriber(destination, parent) {
  112. var _this = _super.call(this, destination) || this;
  113. _this.parent = parent;
  114. return _this;
  115. }
  116. SequenceEqualCompareToSubscriber.prototype._next = function (value) {
  117. this.parent.nextB(value);
  118. };
  119. SequenceEqualCompareToSubscriber.prototype._error = function (err) {
  120. this.parent.error(err);
  121. this.unsubscribe();
  122. };
  123. SequenceEqualCompareToSubscriber.prototype._complete = function () {
  124. this.parent.completeB();
  125. this.unsubscribe();
  126. };
  127. return SequenceEqualCompareToSubscriber;
  128. }(Subscriber_1.Subscriber));
  129. //# sourceMappingURL=sequenceEqual.js.map