distinct.js 785 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((source, subscriber) => {
  7. const distinctKeys = new Set();
  8. source.subscribe(createOperatorSubscriber(subscriber, (value) => {
  9. const 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, () => distinctKeys.clear(), noop));
  16. });
  17. }
  18. //# sourceMappingURL=distinct.js.map