2022-06-08 10:36:39 +00:00
|
|
|
import { operate } from '../util/lift';
|
|
|
|
import { createOperatorSubscriber } from './OperatorSubscriber';
|
|
|
|
import { noop } from '../util/noop';
|
2023-02-08 12:35:10 +00:00
|
|
|
import { innerFrom } from '../observable/innerFrom';
|
2022-06-08 10:36:39 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}));
|
2023-02-08 12:35:10 +00:00
|
|
|
flushes && innerFrom(flushes).subscribe(createOperatorSubscriber(subscriber, () => distinctKeys.clear(), noop));
|
2022-06-08 10:36:39 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
//# sourceMappingURL=distinct.js.map
|