UNPKG

2.04 kBTypeScriptView Raw
1import { Observable } from 'rxjs';
2import { Action, ActionCreator } from '@ngrx/store';
3import { EffectMetadata, EffectConfig, CreateEffectMetadata } from './models';
4declare type DispatchType<T> = T extends {
5 dispatch: infer U;
6} ? U : true;
7declare type ObservableType<T, OriginalType> = T extends false ? OriginalType : Action;
8declare type EffectResult<OT> = Observable<OT> | ((...args: any[]) => Observable<OT>);
9declare type ConditionallyDisallowActionCreator<DT, Result> = DT extends false ? unknown : Result extends EffectResult<infer OT> ? OT extends ActionCreator ? 'ActionCreator cannot be dispatched. Did you forget to call the action creator function?' : unknown : unknown;
10/**
11 * @description
12 * Creates an effect from an `Observable` and an `EffectConfig`.
13 *
14 * @param source A function which returns an `Observable`.
15 * @param config A `Partial<EffectConfig>` to configure the effect. By default, `dispatch` is true and `useEffectsErrorHandler` is true.
16 * @returns If `EffectConfig`#`dispatch` is true, returns `Observable<Action>`. Else, returns `Observable<unknown>`.
17 *
18 * @usageNotes
19 *
20 * ** Mapping to a different action **
21 * ```ts
22 * effectName$ = createEffect(
23 * () => this.actions$.pipe(
24 * ofType(FeatureActions.actionOne),
25 * map(() => FeatureActions.actionTwo())
26 * )
27 * );
28 * ```
29 *
30 * ** Non-dispatching effects **
31 * ```ts
32 * effectName$ = createEffect(
33 * () => this.actions$.pipe(
34 * ofType(FeatureActions.actionOne),
35 * tap(() => console.log('Action One Dispatched'))
36 * ),
37 * { dispatch: false }
38 * // FeatureActions.actionOne is not dispatched
39 * );
40 * ```
41 */
42export declare function createEffect<C extends EffectConfig, DT extends DispatchType<C>, OT extends ObservableType<DT, OT>, R extends EffectResult<OT>>(source: () => R & ConditionallyDisallowActionCreator<DT, R>, config?: Partial<C>): R & CreateEffectMetadata;
43export declare function getCreateEffectMetadata<T extends {
44 [props in keyof T]: Object;
45}>(instance: T): EffectMetadata<T>[];
46export {};
47
\No newline at end of file