sequenceEqual.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.sequenceEqual = void 0;
  4. var lift_1 = require("../util/lift");
  5. var OperatorSubscriber_1 = require("./OperatorSubscriber");
  6. var innerFrom_1 = require("../observable/innerFrom");
  7. function sequenceEqual(compareTo, comparator) {
  8. if (comparator === void 0) { comparator = function (a, b) { return a === b; }; }
  9. return lift_1.operate(function (source, subscriber) {
  10. var aState = createState();
  11. var bState = createState();
  12. var emit = function (isEqual) {
  13. subscriber.next(isEqual);
  14. subscriber.complete();
  15. };
  16. var createSubscriber = function (selfState, otherState) {
  17. var sequenceEqualSubscriber = OperatorSubscriber_1.createOperatorSubscriber(subscriber, function (a) {
  18. var buffer = otherState.buffer, complete = otherState.complete;
  19. if (buffer.length === 0) {
  20. complete ? emit(false) : selfState.buffer.push(a);
  21. }
  22. else {
  23. !comparator(a, buffer.shift()) && emit(false);
  24. }
  25. }, function () {
  26. selfState.complete = true;
  27. var complete = otherState.complete, buffer = otherState.buffer;
  28. complete && emit(buffer.length === 0);
  29. sequenceEqualSubscriber === null || sequenceEqualSubscriber === void 0 ? void 0 : sequenceEqualSubscriber.unsubscribe();
  30. });
  31. return sequenceEqualSubscriber;
  32. };
  33. source.subscribe(createSubscriber(aState, bState));
  34. innerFrom_1.innerFrom(compareTo).subscribe(createSubscriber(bState, aState));
  35. });
  36. }
  37. exports.sequenceEqual = sequenceEqual;
  38. function createState() {
  39. return {
  40. buffer: [],
  41. complete: false,
  42. };
  43. }
  44. //# sourceMappingURL=sequenceEqual.js.map