distinctUntilChanged.js 916 B

1234567891011121314151617181920212223
  1. import { identity } from '../util/identity';
  2. import { operate } from '../util/lift';
  3. import { createOperatorSubscriber } from './OperatorSubscriber';
  4. export function distinctUntilChanged(comparator, keySelector) {
  5. if (keySelector === void 0) { keySelector = identity; }
  6. comparator = comparator !== null && comparator !== void 0 ? comparator : defaultCompare;
  7. return operate(function (source, subscriber) {
  8. var previousKey;
  9. var first = true;
  10. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  11. var currentKey = keySelector(value);
  12. if (first || !comparator(previousKey, currentKey)) {
  13. first = false;
  14. previousKey = currentKey;
  15. subscriber.next(value);
  16. }
  17. }));
  18. });
  19. }
  20. function defaultCompare(a, b) {
  21. return a === b;
  22. }
  23. //# sourceMappingURL=distinctUntilChanged.js.map