distinctUntilChanged.js 1.1 KB

123456789101112131415161718192021222324252627
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.distinctUntilChanged = void 0;
  4. var identity_1 = require("../util/identity");
  5. var lift_1 = require("../util/lift");
  6. var OperatorSubscriber_1 = require("./OperatorSubscriber");
  7. function distinctUntilChanged(comparator, keySelector) {
  8. if (keySelector === void 0) { keySelector = identity_1.identity; }
  9. comparator = comparator !== null && comparator !== void 0 ? comparator : defaultCompare;
  10. return lift_1.operate(function (source, subscriber) {
  11. var previousKey;
  12. var first = true;
  13. source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function (value) {
  14. var currentKey = keySelector(value);
  15. if (first || !comparator(previousKey, currentKey)) {
  16. first = false;
  17. previousKey = currentKey;
  18. subscriber.next(value);
  19. }
  20. }));
  21. });
  22. }
  23. exports.distinctUntilChanged = distinctUntilChanged;
  24. function defaultCompare(a, b) {
  25. return a === b;
  26. }
  27. //# sourceMappingURL=distinctUntilChanged.js.map