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(function (source, subscriber) {
|
|
|
|
var distinctKeys = new Set();
|
|
|
|
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
|
|
var 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, function () { return distinctKeys.clear(); }, noop));
|
2022-06-08 10:36:39 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
//# sourceMappingURL=distinct.js.map
|