This repository has been archived on 2024-07-27. You can view files and clone it, but cannot push or open issues or pull requests.
keksAccountGUI/node_modulesOLD/rxjs/_esm2015/internal/operators/distinctUntilChanged.js
2019-08-11 20:48:02 +02:00

54 lines
No EOL
1.6 KiB
JavaScript

import { Subscriber } from '../Subscriber';
export function distinctUntilChanged(compare, keySelector) {
return (source) => source.lift(new DistinctUntilChangedOperator(compare, keySelector));
}
class DistinctUntilChangedOperator {
constructor(compare, keySelector) {
this.compare = compare;
this.keySelector = keySelector;
}
call(subscriber, source) {
return source.subscribe(new DistinctUntilChangedSubscriber(subscriber, this.compare, this.keySelector));
}
}
class DistinctUntilChangedSubscriber extends Subscriber {
constructor(destination, compare, keySelector) {
super(destination);
this.keySelector = keySelector;
this.hasKey = false;
if (typeof compare === 'function') {
this.compare = compare;
}
}
compare(x, y) {
return x === y;
}
_next(value) {
let key;
try {
const { keySelector } = this;
key = keySelector ? keySelector(value) : value;
}
catch (err) {
return this.destination.error(err);
}
let result = false;
if (this.hasKey) {
try {
const { compare } = this;
result = compare(this.key, key);
}
catch (err) {
return this.destination.error(err);
}
}
else {
this.hasKey = true;
}
if (!result) {
this.key = key;
this.destination.next(value);
}
}
}
//# sourceMappingURL=distinctUntilChanged.js.map