@equinor/fusion-observable
Version:
14 lines (11 loc) • 533 B
text/typescript
import { type OperatorFunction, type ObservableInput, switchMap } from 'rxjs';
import { filterAction } from './filter-action';
import type { Action, ActionType, ExtractAction } from '../types';
export const switchMapAction =
<TAction extends Action, TType extends ActionType<TAction>, TResult>(
type: TType,
fn: (value: ExtractAction<TAction, TType>) => ObservableInput<TResult>,
): OperatorFunction<TAction, TResult> =>
(source) =>
source.pipe(filterAction(type), switchMap(fn));
export default switchMapAction;