Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(effects): accept ObservableInput as concatLatestFrom argument #3838

26 changes: 12 additions & 14 deletions modules/effects/src/concat_latest_from.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Observable, ObservedValueOf, of, OperatorFunction, pipe } from 'rxjs';
import { Observable, ObservableInput, of, ObservedValueOf, OperatorFunction } from 'rxjs';
import { concatMap, withLatestFrom } from 'rxjs/operators';
markostanimirovic marked this conversation as resolved.
Show resolved Hide resolved

// The array overload is needed first because we want to maintain the proper order in the resulting tuple
Expand Down Expand Up @@ -38,24 +38,22 @@ export function concatLatestFrom<T extends Observable<unknown>, V>(
* ```
*/
export function concatLatestFrom<
T extends Observable<unknown>[] | Observable<unknown>,
T extends ObservableInput<unknown>[] | ObservableInput<unknown>,
V,
R = [
V,
...(T extends Observable<unknown>[]
...(T extends ObservableInput<unknown>[]
? { [i in keyof T]: ObservedValueOf<T[i]> }
: [ObservedValueOf<T>])
]
>(observablesFactory: (value: V) => T): OperatorFunction<V, R> {
return pipe(
concatMap((value) => {
const observables = observablesFactory(value);
const observablesAsArray = Array.isArray(observables)
? observables
: [observables];
return of(value).pipe(
withLatestFrom(...observablesAsArray)
) as unknown as Observable<R>;
})
);
return concatMap((value) => {
const observables = observablesFactory(value);
const observablesAsArray = Array.isArray(observables)
? observables
: [observables];
return of(value).pipe(
withLatestFrom(...observablesAsArray)
) as unknown as Observable<R>;
})
}