@ngrx/effects

  • Version 13.2.0
  • Published
  • 542 kB
  • 1 dependency
  • MIT license

Install

npm i @ngrx/effects
yarn add @ngrx/effects
pnpm add @ngrx/effects

Overview

Side effect model for @ngrx/store

Index

Variables

variable EFFECTS_ERROR_HANDLER

const EFFECTS_ERROR_HANDLER: InjectionToken<EffectsErrorHandler>;

    variable ROOT_EFFECTS_INIT

    const ROOT_EFFECTS_INIT: string;

      variable rootEffectsInit

      const rootEffectsInit: any;

        variable USER_PROVIDED_EFFECTS

        const USER_PROVIDED_EFFECTS: InjectionToken<Type<any>[][]>;

          Functions

          function act

          act: {
          <Input, OutputAction extends Action, ErrorAction extends Action>(
          project: (input: Input, index: number) => Observable<OutputAction>,
          error: (error: any, input: Input) => ErrorAction
          ): (source: Observable<Input>) => Observable<OutputAction | ErrorAction>;
          <
          Input,
          OutputAction extends Action,
          ErrorAction extends Action,
          CompleteAction extends Action = never,
          UnsubscribeAction extends Action = never
          >(
          config: ActConfig<
          Input,
          OutputAction,
          ErrorAction,
          CompleteAction,
          UnsubscribeAction
          >
          ): (
          source: Observable<Input>
          ) => Observable<OutputAction | ErrorAction | CompleteAction | UnsubscribeAction>;
          };

            function concatLatestFrom

            concatLatestFrom: {
            <T extends Observable<unknown>[], V>(
            observablesFactory: (value: V) => [...T]
            ): OperatorFunction<V, [V, ...{ [i in keyof T]: ObservedValueOf<T[i]> }]>;
            <T extends Observable<unknown>, V>(
            observableFactory: (value: V) => T
            ): OperatorFunction<V, [V, ObservedValueOf<T>]>;
            };

              function createEffect

              createEffect: <
              C extends EffectConfig,
              DT extends DispatchType<C>,
              OT extends ObservableType<DT, OT>,
              R extends unknown
              >(
              source: () => R & ConditionallyDisallowActionCreator<DT, R>,
              config?: Partial<C>
              ) => R & CreateEffectMetadata;
              • Creates an effect from an Observable and an EffectConfig.

                Parameter source

                A function which returns an Observable.

                Parameter config

                A Partial<EffectConfig> to configure the effect. By default, dispatch is true and useEffectsErrorHandler is true.

                Returns

                If EffectConfig#dispatch is true, returns Observable<Action>. Else, returns Observable<unknown>.

                ** Mapping to a different action **

                effectName$ = createEffect(
                () => this.actions$.pipe(
                ofType(FeatureActions.actionOne),
                map(() => FeatureActions.actionTwo())
                )
                );

                ** Non-dispatching effects **

                effectName$ = createEffect(
                () => this.actions$.pipe(
                ofType(FeatureActions.actionOne),
                tap(() => console.log('Action One Dispatched'))
                ),
                { dispatch: false }
                // FeatureActions.actionOne is not dispatched
                );

              function defaultEffectsErrorHandler

              defaultEffectsErrorHandler: <T extends Action>(
              observable$: Observable<T>,
              errorHandler: ErrorHandler,
              retryAttemptLeft?: number
              ) => Observable<T>;

                function Effect

                Effect: (
                config?: EffectConfig
                ) => <T extends Object, K extends Exclude<keyof T, keyof Object>>(
                target: T,
                propertyName: K
                ) => void;

                function getEffectsMetadata

                getEffectsMetadata: <T>(instance: T) => EffectsMetadata<T>;

                  function mergeEffects

                  mergeEffects: (
                  sourceInstance: any,
                  globalErrorHandler: ErrorHandler,
                  effectsErrorHandler: EffectsErrorHandler
                  ) => Observable<EffectNotification>;

                    function ofType

                    ofType: {
                    <
                    AC extends ActionCreator<string, Creator>[],
                    U extends Action = Action,
                    V = ReturnType<AC[number]>
                    >(
                    ...allowedTypes: AC
                    ): OperatorFunction<U, V>;
                    <
                    E extends Extract<U, { type: T1 }>,
                    AC extends ActionCreator<string, Creator>,
                    T1 extends string | AC,
                    U extends Action = Action,
                    V = T1 extends string ? E : ReturnType<Extract<T1, AC>>
                    >(
                    t1: T1
                    ): OperatorFunction<U, V>;
                    <
                    E extends Extract<U, { type: T1 | T2 }>,
                    AC extends ActionCreator<string, Creator>,
                    T1 extends string | AC,
                    T2 extends string | AC,
                    U extends Action = Action,
                    V = ActionExtractor<T1, AC, E> | ActionExtractor<T2, AC, E>
                    >(
                    t1: T1,
                    t2: T2
                    ): OperatorFunction<U, V>;
                    <
                    E extends Extract<U, { type: T1 | T2 | T3 }>,
                    AC extends ActionCreator<string, Creator>,
                    T1 extends string | AC,
                    T2 extends string | AC,
                    T3 extends string | AC,
                    U extends Action = Action,
                    V =
                    | ActionExtractor<T1, AC, E>
                    | ActionExtractor<T2, AC, E>
                    | ActionExtractor<T3, AC, E>
                    >(
                    t1: T1,
                    t2: T2,
                    t3: T3
                    ): OperatorFunction<U, V>;
                    <
                    E extends Extract<U, { type: T1 | T2 | T3 | T4 }>,
                    AC extends ActionCreator<string, Creator>,
                    T1 extends string | AC,
                    T2 extends string | AC,
                    T3 extends string | AC,
                    T4 extends string | AC,
                    U extends Action = Action,
                    V =
                    | ActionExtractor<T1, AC, E>
                    | ActionExtractor<T2, AC, E>
                    | ActionExtractor<T3, AC, E>
                    | ActionExtractor<T4, AC, E>
                    >(
                    t1: T1,
                    t2: T2,
                    t3: T3,
                    t4: T4
                    ): OperatorFunction<U, V>;
                    <
                    E extends Extract<U, { type: T1 | T2 | T3 | T4 | T5 }>,
                    AC extends ActionCreator<string, Creator>,
                    T1 extends string | AC,
                    T2 extends string | AC,
                    T3 extends string | AC,
                    T4 extends string | AC,
                    T5 extends string | AC,
                    U extends Action = Action,
                    V =
                    | ActionExtractor<T1, AC, E>
                    | ActionExtractor<T2, AC, E>
                    | ActionExtractor<T3, AC, E>
                    | ActionExtractor<T4, AC, E>
                    | ActionExtractor<T5, AC, E>
                    >(
                    t1: T1,
                    t2: T2,
                    t3: T3,
                    t4: T4,
                    t5: T5
                    ): OperatorFunction<U, V>;
                    <V extends Action>(...allowedTypes: any[]): OperatorFunction<Action, V>;
                    };
                    • Fallback for more than 5 arguments. There is no inference, so the return type is the same as the input - Observable.

                      We provide a type parameter, even though TS will not infer it from the arguments, to preserve backwards compatibility with old versions of ngrx.

                    Classes

                    class Actions

                    class Actions<V = Action> extends Observable<V> {}

                      constructor

                      constructor(source?: Observable<V>);

                        property ɵfac

                        static ɵfac: i0.ɵɵFactoryDeclaration<Actions<any>, never>;

                          property ɵprov

                          static ɵprov: i0.ɵɵInjectableDeclaration<Actions<any>>;

                            method lift

                            lift: <R>(operator: Operator<V, R>) => Observable<R>;

                              class EffectsFeatureModule

                              class EffectsFeatureModule {}

                                constructor

                                constructor(
                                root: EffectsRootModule,
                                effectSourceGroups: any[][],
                                storeRootModule: StoreRootModule,
                                storeFeatureModule: StoreFeatureModule
                                );

                                  property ɵfac

                                  static ɵfac: i0.ɵɵFactoryDeclaration<
                                  EffectsFeatureModule,
                                  [null, null, { optional: true }, { optional: true }]
                                  >;

                                    property ɵinj

                                    static ɵinj: i0.ɵɵInjectorDeclaration<EffectsFeatureModule>;

                                      property ɵmod

                                      static ɵmod: i0.ɵɵNgModuleDeclaration<EffectsFeatureModule, never, never, never>;

                                        class EffectsModule

                                        class EffectsModule {}

                                          property ɵfac

                                          static ɵfac: i0.ɵɵFactoryDeclaration<EffectsModule, never>;

                                            property ɵinj

                                            static ɵinj: i0.ɵɵInjectorDeclaration<EffectsModule>;

                                              property ɵmod

                                              static ɵmod: i0.ɵɵNgModuleDeclaration<EffectsModule, never, never, never>;

                                                method forFeature

                                                static forFeature: (
                                                featureEffects?: Type<any>[]
                                                ) => ModuleWithProviders<EffectsFeatureModule>;

                                                  method forRoot

                                                  static forRoot: (
                                                  rootEffects?: Type<any>[]
                                                  ) => ModuleWithProviders<EffectsRootModule>;

                                                    class EffectSources

                                                    class EffectSources extends Subject<any> {}

                                                      constructor

                                                      constructor(
                                                      errorHandler: ErrorHandler,
                                                      effectsErrorHandler: EffectsErrorHandler
                                                      );

                                                        property ɵfac

                                                        static ɵfac: i0.ɵɵFactoryDeclaration<EffectSources, never>;

                                                          property ɵprov

                                                          static ɵprov: i0.ɵɵInjectableDeclaration<EffectSources>;

                                                            method addEffects

                                                            addEffects: (effectSourceInstance: any) => void;

                                                              class EffectsRootModule

                                                              class EffectsRootModule {}

                                                                constructor

                                                                constructor(
                                                                sources: EffectSources,
                                                                runner: EffectsRunner,
                                                                store: Store<any>,
                                                                rootEffects: any[],
                                                                storeRootModule: StoreRootModule,
                                                                storeFeatureModule: StoreFeatureModule,
                                                                guard: any
                                                                );

                                                                  property ɵfac

                                                                  static ɵfac: i0.ɵɵFactoryDeclaration<
                                                                  EffectsRootModule,
                                                                  [
                                                                  null,
                                                                  null,
                                                                  null,
                                                                  null,
                                                                  { optional: true },
                                                                  { optional: true },
                                                                  { optional: true }
                                                                  ]
                                                                  >;

                                                                    property ɵinj

                                                                    static ɵinj: i0.ɵɵInjectorDeclaration<EffectsRootModule>;

                                                                      property ɵmod

                                                                      static ɵmod: i0.ɵɵNgModuleDeclaration<EffectsRootModule, never, never, never>;

                                                                        method addEffects

                                                                        addEffects: (effectSourceInstance: any) => void;

                                                                          class EffectsRunner

                                                                          class EffectsRunner implements OnDestroy {}

                                                                            constructor

                                                                            constructor(effectSources: EffectSources, store: Store<any>);

                                                                              property ɵfac

                                                                              static ɵfac: i0.ɵɵFactoryDeclaration<EffectsRunner, never>;

                                                                                property ɵprov

                                                                                static ɵprov: i0.ɵɵInjectableDeclaration<EffectsRunner>;

                                                                                  method ngOnDestroy

                                                                                  ngOnDestroy: () => void;

                                                                                    method start

                                                                                    start: () => void;

                                                                                      Interfaces

                                                                                      interface CreateEffectMetadata

                                                                                      interface CreateEffectMetadata {}

                                                                                        property [CREATE_EFFECT_METADATA_KEY]

                                                                                        [CREATE_EFFECT_METADATA_KEY]: EffectConfig;

                                                                                          interface EffectConfig

                                                                                          interface EffectConfig {}
                                                                                          • Configures an effect created by createEffect.

                                                                                          property dispatch

                                                                                          dispatch?: boolean;
                                                                                          • Determines if the action emitted by the effect is dispatched to the store. If false, effect does not need to return type Observable<Action>.

                                                                                          property useEffectsErrorHandler

                                                                                          useEffectsErrorHandler?: boolean;
                                                                                          • Determines if the effect will be resubscribed to if an error occurs in the main actions stream.

                                                                                          interface EffectNotification

                                                                                          interface EffectNotification {}

                                                                                            property effect

                                                                                            effect: Observable<any> | (() => Observable<any>);

                                                                                              property notification

                                                                                              notification: Notification<Action | null | undefined>;

                                                                                                property propertyName

                                                                                                propertyName: PropertyKey;

                                                                                                  property sourceInstance

                                                                                                  sourceInstance: any;

                                                                                                    property sourceName

                                                                                                    sourceName: string;

                                                                                                      interface OnIdentifyEffects

                                                                                                      interface OnIdentifyEffects {}
                                                                                                      • Interface to set an identifier for effect instances.

                                                                                                        By default, each Effects class is registered once regardless of how many times the Effect class is loaded. By implementing this interface, you define a unique identifier to register an Effects class instance multiple times.

                                                                                                        ### Set an identifier for an Effects class

                                                                                                        class EffectWithIdentifier implements OnIdentifyEffects {
                                                                                                        constructor(private effectIdentifier: string) {}
                                                                                                        ngrxOnIdentifyEffects() {
                                                                                                        return this.effectIdentifier;
                                                                                                        }

                                                                                                      method ngrxOnIdentifyEffects

                                                                                                      ngrxOnIdentifyEffects: () => string;
                                                                                                      • String identifier to differentiate effect instances.

                                                                                                      interface OnInitEffects

                                                                                                      interface OnInitEffects {}
                                                                                                      • Interface to dispatch an action after effect registration.

                                                                                                        Implement this interface to dispatch a custom action after the effect has been added. You can listen to this action in the rest of the application to execute something after the effect is registered.

                                                                                                        ### Set an identifier for an Effects class

                                                                                                        class EffectWithInitAction implements OnInitEffects {
                                                                                                        ngrxOnInitEffects() {
                                                                                                        return { type: '[EffectWithInitAction] Init' };
                                                                                                        }

                                                                                                      method ngrxOnInitEffects

                                                                                                      ngrxOnInitEffects: () => Action;
                                                                                                      • Action to be dispatched after the effect is registered.

                                                                                                      interface OnRunEffects

                                                                                                      interface OnRunEffects {}
                                                                                                      • Interface to control the lifecycle of effects.

                                                                                                        By default, effects are merged and subscribed to the store. Implement the OnRunEffects interface to control the lifecycle of the resolved effects.

                                                                                                        ### Implement the OnRunEffects interface on an Effects class

                                                                                                        export class UserEffects implements OnRunEffects {
                                                                                                        constructor(private actions$: Actions) {}
                                                                                                        ngrxOnRunEffects(resolvedEffects$: Observable<EffectNotification>) {
                                                                                                        return this.actions$.pipe(
                                                                                                        ofType('LOGGED_IN'),
                                                                                                        exhaustMap(() =>
                                                                                                        resolvedEffects$.pipe(
                                                                                                        takeUntil(this.actions$.pipe(ofType('LOGGED_OUT')))
                                                                                                        )
                                                                                                        )
                                                                                                        );
                                                                                                        }
                                                                                                        }

                                                                                                      method ngrxOnRunEffects

                                                                                                      ngrxOnRunEffects: (
                                                                                                      resolvedEffects$: Observable<EffectNotification>
                                                                                                      ) => Observable<EffectNotification>;
                                                                                                      • Method to control the lifecycle of effects.

                                                                                                      Type Aliases

                                                                                                      type EffectsErrorHandler

                                                                                                      type EffectsErrorHandler = <T extends Action>(
                                                                                                      observable$: Observable<T>,
                                                                                                      errorHandler: ErrorHandler
                                                                                                      ) => Observable<T>;

                                                                                                        type EffectsMetadata

                                                                                                        type EffectsMetadata<T> = {
                                                                                                        [key in EffectPropertyKey<T>]?: EffectConfig;
                                                                                                        };

                                                                                                          Package Files (18)

                                                                                                          Dependencies (1)

                                                                                                          Dev Dependencies (0)

                                                                                                          No dev dependencies.

                                                                                                          Peer Dependencies (3)

                                                                                                          Badge

                                                                                                          To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                          You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@ngrx/effects.

                                                                                                          • Markdown
                                                                                                            [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@ngrx/effects)
                                                                                                          • HTML
                                                                                                            <a href="https://www.jsdocs.io/package/@ngrx/effects"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>