| 1 |
import { identity } from '../util/identity'; |
| 2 |
import { operate } from '../util/lift'; |
| 3 |
import { createOperatorSubscriber } from './OperatorSubscriber'; |
| 4 |
export function distinctUntilChanged(comparator, keySelector = identity) { |
| 5 |
comparator = comparator !== null && comparator !== void 0 ? comparator : defaultCompare; |
| 6 |
return operate((source, subscriber) => { |
| 7 |
let previousKey; |
| 8 |
let first = true; |
| 9 |
source.subscribe(createOperatorSubscriber(subscriber, (value) => { |
| 10 |
const currentKey = keySelector(value); |
| 11 |
if (first || !comparator(previousKey, currentKey)) { |
| 12 |
first = false; |
| 13 |
previousKey = currentKey; |
| 14 |
subscriber.next(value); |
| 15 |
} |
| 16 |
})); |
| 17 |
}); |
| 18 |
} |
| 19 |
function defaultCompare(a, b) { |
| 20 |
return a === b; |
| 21 |
} |
| 22 |
//# sourceMappingURL=distinctUntilChanged.js.map |