mirror of
https://github.com/re-rxjs/react-rxjs.git
synced 2025-12-08 18:01:51 +00:00
16 lines
575 B
TypeScript
16 lines
575 B
TypeScript
import { ObservableInput, OperatorFunction, ObservedValueOf, pipe } from "rxjs"
|
|
import { switchMap } from "rxjs/operators"
|
|
import { suspend } from "./suspend"
|
|
import { SUSPENSE } from "@react-rxjs/core"
|
|
|
|
/**
|
|
* Same behaviour as rxjs' `switchMap`, but prepending every new event with
|
|
* SUSPENSE.
|
|
*
|
|
* @param fn Projection function
|
|
*/
|
|
export const switchMapSuspended = <T, O extends ObservableInput<any>>(
|
|
project: (value: T, index: number) => O,
|
|
): OperatorFunction<T, ObservedValueOf<O> | typeof SUSPENSE> =>
|
|
pipe(switchMap((x, index) => suspend(project(x, index))))
|