sequenceEqual.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */
  2. import * as tslib_1 from "tslib";
  3. import { Subscriber } from '../Subscriber';
  4. export function sequenceEqual(compareTo, comparator) {
  5. return function (source) { return source.lift(new SequenceEqualOperator(compareTo, comparator)); };
  6. }
  7. var SequenceEqualOperator = /*@__PURE__*/ (function () {
  8. function SequenceEqualOperator(compareTo, comparator) {
  9. this.compareTo = compareTo;
  10. this.comparator = comparator;
  11. }
  12. SequenceEqualOperator.prototype.call = function (subscriber, source) {
  13. return source.subscribe(new SequenceEqualSubscriber(subscriber, this.compareTo, this.comparator));
  14. };
  15. return SequenceEqualOperator;
  16. }());
  17. export { SequenceEqualOperator };
  18. var SequenceEqualSubscriber = /*@__PURE__*/ (function (_super) {
  19. tslib_1.__extends(SequenceEqualSubscriber, _super);
  20. function SequenceEqualSubscriber(destination, compareTo, comparator) {
  21. var _this = _super.call(this, destination) || this;
  22. _this.compareTo = compareTo;
  23. _this.comparator = comparator;
  24. _this._a = [];
  25. _this._b = [];
  26. _this._oneComplete = false;
  27. _this.destination.add(compareTo.subscribe(new SequenceEqualCompareToSubscriber(destination, _this)));
  28. return _this;
  29. }
  30. SequenceEqualSubscriber.prototype._next = function (value) {
  31. if (this._oneComplete && this._b.length === 0) {
  32. this.emit(false);
  33. }
  34. else {
  35. this._a.push(value);
  36. this.checkValues();
  37. }
  38. };
  39. SequenceEqualSubscriber.prototype._complete = function () {
  40. if (this._oneComplete) {
  41. this.emit(this._a.length === 0 && this._b.length === 0);
  42. }
  43. else {
  44. this._oneComplete = true;
  45. }
  46. this.unsubscribe();
  47. };
  48. SequenceEqualSubscriber.prototype.checkValues = function () {
  49. var _c = this, _a = _c._a, _b = _c._b, comparator = _c.comparator;
  50. while (_a.length > 0 && _b.length > 0) {
  51. var a = _a.shift();
  52. var b = _b.shift();
  53. var areEqual = false;
  54. try {
  55. areEqual = comparator ? comparator(a, b) : a === b;
  56. }
  57. catch (e) {
  58. this.destination.error(e);
  59. }
  60. if (!areEqual) {
  61. this.emit(false);
  62. }
  63. }
  64. };
  65. SequenceEqualSubscriber.prototype.emit = function (value) {
  66. var destination = this.destination;
  67. destination.next(value);
  68. destination.complete();
  69. };
  70. SequenceEqualSubscriber.prototype.nextB = function (value) {
  71. if (this._oneComplete && this._a.length === 0) {
  72. this.emit(false);
  73. }
  74. else {
  75. this._b.push(value);
  76. this.checkValues();
  77. }
  78. };
  79. SequenceEqualSubscriber.prototype.completeB = function () {
  80. if (this._oneComplete) {
  81. this.emit(this._a.length === 0 && this._b.length === 0);
  82. }
  83. else {
  84. this._oneComplete = true;
  85. }
  86. };
  87. return SequenceEqualSubscriber;
  88. }(Subscriber));
  89. export { SequenceEqualSubscriber };
  90. var SequenceEqualCompareToSubscriber = /*@__PURE__*/ (function (_super) {
  91. tslib_1.__extends(SequenceEqualCompareToSubscriber, _super);
  92. function SequenceEqualCompareToSubscriber(destination, parent) {
  93. var _this = _super.call(this, destination) || this;
  94. _this.parent = parent;
  95. return _this;
  96. }
  97. SequenceEqualCompareToSubscriber.prototype._next = function (value) {
  98. this.parent.nextB(value);
  99. };
  100. SequenceEqualCompareToSubscriber.prototype._error = function (err) {
  101. this.parent.error(err);
  102. this.unsubscribe();
  103. };
  104. SequenceEqualCompareToSubscriber.prototype._complete = function () {
  105. this.parent.completeB();
  106. this.unsubscribe();
  107. };
  108. return SequenceEqualCompareToSubscriber;
  109. }(Subscriber));
  110. //# sourceMappingURL=sequenceEqual.js.map