wishthis/node_modules/rxjs/dist/esm/internal/operators/distinct.js
2023-02-08 13:35:10 +01:00

18 lines
No EOL
785 B
JavaScript

import { operate } from '../util/lift';
import { createOperatorSubscriber } from './OperatorSubscriber';
import { noop } from '../util/noop';
import { innerFrom } from '../observable/innerFrom';
export function distinct(keySelector, flushes) {
return operate((source, subscriber) => {
const distinctKeys = new Set();
source.subscribe(createOperatorSubscriber(subscriber, (value) => {
const key = keySelector ? keySelector(value) : value;
if (!distinctKeys.has(key)) {
distinctKeys.add(key);
subscriber.next(value);
}
}));
flushes && innerFrom(flushes).subscribe(createOperatorSubscriber(subscriber, () => distinctKeys.clear(), noop));
});
}
//# sourceMappingURL=distinct.js.map