distinct.js
1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { SimpleOuterSubscriber, innerSubscribe, SimpleInnerSubscriber } from '../innerSubscribe';
export function distinct(keySelector, flushes) {
return (source) => source.lift(new DistinctOperator(keySelector, flushes));
}
class DistinctOperator {
constructor(keySelector, flushes) {
this.keySelector = keySelector;
this.flushes = flushes;
}
call(subscriber, source) {
return source.subscribe(new DistinctSubscriber(subscriber, this.keySelector, this.flushes));
}
}
export class DistinctSubscriber extends SimpleOuterSubscriber {
constructor(destination, keySelector, flushes) {
super(destination);
this.keySelector = keySelector;
this.values = new Set();
if (flushes) {
this.add(innerSubscribe(flushes, new SimpleInnerSubscriber(this)));
}
}
notifyNext() {
this.values.clear();
}
notifyError(error) {
this._error(error);
}
_next(value) {
if (this.keySelector) {
this._useKeySelector(value);
}
else {
this._finalizeNext(value, value);
}
}
_useKeySelector(value) {
let key;
const { destination } = this;
try {
key = this.keySelector(value);
}
catch (err) {
destination.error(err);
return;
}
this._finalizeNext(key, value);
}
_finalizeNext(key, value) {
const { values } = this;
if (!values.has(key)) {
values.add(key);
this.destination.next(value);
}
}
}
//# sourceMappingURL=distinct.js.map