Skip to content

Commit 7191904

Browse files
committed
feat(distinct): distinct's flush supports ObservableInput
1 parent afac3d5 commit 7191904

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

api_guard/dist/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export declare function delayWhen<T>(delayDurationSelector: (value: T, index: nu
160160

161161
export declare function dematerialize<N extends ObservableNotification<any>>(): OperatorFunction<N, ValueFromNotification<N>>;
162162

163-
export declare function distinct<T, K>(keySelector?: (value: T) => K, flushes?: Observable<any>): MonoTypeOperatorFunction<T>;
163+
export declare function distinct<T, K>(keySelector?: (value: T) => K, flushes?: ObservableInput<any>): MonoTypeOperatorFunction<T>;
164164

165165
export declare function distinctUntilChanged<T>(comparator?: (previous: T, current: T) => boolean): MonoTypeOperatorFunction<T>;
166166
export declare function distinctUntilChanged<T, K>(comparator: (previous: K, current: K) => boolean, keySelector: (value: T) => K): MonoTypeOperatorFunction<T>;

api_guard/dist/types/operators/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export declare function delayWhen<T>(delayDurationSelector: (value: T, index: nu
7272

7373
export declare function dematerialize<N extends ObservableNotification<any>>(): OperatorFunction<N, ValueFromNotification<N>>;
7474

75-
export declare function distinct<T, K>(keySelector?: (value: T) => K, flushes?: Observable<any>): MonoTypeOperatorFunction<T>;
75+
export declare function distinct<T, K>(keySelector?: (value: T) => K, flushes?: ObservableInput<any>): MonoTypeOperatorFunction<T>;
7676

7777
export declare function distinctUntilChanged<T>(comparator?: (previous: T, current: T) => boolean): MonoTypeOperatorFunction<T>;
7878
export declare function distinctUntilChanged<T, K>(comparator: (previous: K, current: K) => boolean, keySelector: (value: T) => K): MonoTypeOperatorFunction<T>;

src/internal/operators/distinct.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Observable } from '../Observable';
2-
import { MonoTypeOperatorFunction } from '../types';
1+
import { InteropObservable, MonoTypeOperatorFunction, ObservableInput } from '../types';
32
import { operate } from '../util/lift';
43
import { createOperatorSubscriber } from './OperatorSubscriber';
54
import { noop } from '../util/noop';
5+
import { isInteropObservable } from '../util/isInteropObservable';
6+
import { fromInteropObservable } from '../observable/innerFrom';
67

78
/**
89
* Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from previous items.
@@ -57,11 +58,11 @@ import { noop } from '../util/noop';
5758
* @see {@link distinctUntilKeyChanged}
5859
*
5960
* @param {function} [keySelector] Optional function to select which value you want to check as distinct.
60-
* @param {Observable} [flushes] Optional Observable for flushing the internal HashSet of the operator.
61+
* @param {ObservableInput} [flushes] Optional ObservableInput for flushing the internal HashSet of the operator.
6162
* @return A function that returns an Observable that emits items from the
6263
* source Observable with distinct values.
6364
*/
64-
export function distinct<T, K>(keySelector?: (value: T) => K, flushes?: Observable<any>): MonoTypeOperatorFunction<T> {
65+
export function distinct<T, K>(keySelector?: (value: T) => K, flushes?: ObservableInput<any>): MonoTypeOperatorFunction<T> {
6566
return operate((source, subscriber) => {
6667
const distinctKeys = new Set();
6768
source.subscribe(
@@ -74,6 +75,11 @@ export function distinct<T, K>(keySelector?: (value: T) => K, flushes?: Observab
7475
})
7576
);
7677

77-
flushes?.subscribe(createOperatorSubscriber(subscriber, () => distinctKeys.clear(), noop));
78+
let flush$ = flushes as InteropObservable<any> | ObservableInput<any> | undefined | any;
79+
if (flushes && isInteropObservable(flushes)) {
80+
flush$ = fromInteropObservable(flushes);
81+
}
82+
83+
flush$?.subscribe(createOperatorSubscriber(subscriber, () => distinctKeys.clear(), noop));
7884
});
7985
}

0 commit comments

Comments
 (0)