distinct.js 811 B

123456789101112131415161718
  1. import { operate } from '../util/lift';
  2. import { createOperatorSubscriber } from './OperatorSubscriber';
  3. import { noop } from '../util/noop';
  4. import { innerFrom } from '../observable/innerFrom';
  5. export function distinct(keySelector, flushes) {
  6. return operate(function (source, subscriber) {
  7. var distinctKeys = new Set();
  8. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  9. var key = keySelector ? keySelector(value) : value;
  10. if (!distinctKeys.has(key)) {
  11. distinctKeys.add(key);
  12. subscriber.next(value);
  13. }
  14. }));
  15. flushes && innerFrom(flushes).subscribe(createOperatorSubscriber(subscriber, function () { return distinctKeys.clear(); }, noop));
  16. });
  17. }
  18. //# sourceMappingURL=distinct.js.map