switchMap()
Function
switchMap<I, R>(switchMapFn:
Function
):MaybeCancellingPipeOperator
<I
,ReadReturn
<R
>,IsCancellingRead
<R
>>
Maps a value to a different Read using the switchMapFn.
ts
// without cancelling reads
declare const read1: Read<string>;
declare const mappedRead: Read<number>;
const read: Read<number> = read1.pipe(switchMap((value: string) => mappedRead));
ts
// with cancelling source read
declare const read1: Read<string, true>;
declare const mappedRead: Read<number>;
const read: Read<number, true> = read1.pipe(switchMap((value: string) => mappedRead));
ts
// with cancelling mapped read
declare const read1: Read<string>;
declare const mappedRead: Read<number, true>;
const read: Read<number, true> = read1.pipe(switchMap((value: string) => mappedRead));
Observable Behavior:
Works exactly like switchMap of RxJS.
Sync Behavior:
Maps the current value to a new Read using its sync value to continue or cancel the chain.
Source: rxjs-read/src/lib/operators/switch-map.ts:51
Type parameters
Parameter | Description |
---|---|
I | type of the input value |
R extends Read <unknown , boolean > | type of the return value |
Parameters
Parameter | Type | Description |
---|---|---|
switchMapFn | (value: I ) => R | function used to map the value to a Read |
Returns
MaybeCancellingPipeOperator
<I
, ReadReturn
<R
>, IsCancellingRead
<R
>>