@ngrx/effects

  • Version 12.5.0
  • Published
  • 588 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: any;

    variable ɵd

    const ɵd: any;

      variable ɵe

      const ɵe: any;

        variable ɵf

        const ɵf: any;

          variable ɵg

          const ɵg: any;

            variable ɵh

            const ɵh: any;

              variable ROOT_EFFECTS_INIT

              const ROOT_EFFECTS_INIT: string;

                variable rootEffectsInit

                const rootEffectsInit: any;

                  variable USER_PROVIDED_EFFECTS

                  const USER_PROVIDED_EFFECTS: any;

                    Functions

                    function act

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

                      function concatLatestFrom

                      concatLatestFrom: {
                      <T extends any[], V>(observablesFactory: (value: V) => [...T]): any;
                      <T extends any, V>(observableFactory: (value: V) => T): any;
                      };

                        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 any>(
                        observable$: any,
                        errorHandler: any,
                        retryAttemptLeft?: number
                        ) => any;

                          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: any,
                            effectsErrorHandler: EffectsErrorHandler
                            ) => any;

                              function ofType

                              ofType: {
                              <AC extends any[], U extends any = any, V = ReturnType<AC[number]>>(
                              ...allowedTypes: AC
                              ): any;
                              <
                              E extends Extract<U, { type: T1 }>,
                              AC extends any,
                              T1 extends string | AC,
                              U extends any = any,
                              V = T1 extends string ? E : ReturnType<Extract<T1, AC>>
                              >(
                              t1: T1
                              ): any;
                              <
                              E extends Extract<U, { type: T1 | T2 }>,
                              AC extends any,
                              T1 extends string | AC,
                              T2 extends string | AC,
                              U extends any = any,
                              V = ActionExtractor<T1, AC, E> | ActionExtractor<T2, AC, E>
                              >(
                              t1: T1,
                              t2: T2
                              ): any;
                              <
                              E extends Extract<U, { type: T1 | T2 | T3 }>,
                              AC extends any,
                              T1 extends string | AC,
                              T2 extends string | AC,
                              T3 extends string | AC,
                              U extends any = any,
                              V =
                              | ActionExtractor<T1, AC, E>
                              | ActionExtractor<T2, AC, E>
                              | ActionExtractor<T3, AC, E>
                              >(
                              t1: T1,
                              t2: T2,
                              t3: T3
                              ): any;
                              <
                              E extends Extract<U, { type: T1 | T2 | T3 | T4 }>,
                              AC extends any,
                              T1 extends string | AC,
                              T2 extends string | AC,
                              T3 extends string | AC,
                              T4 extends string | AC,
                              U extends any = any,
                              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
                              ): any;
                              <
                              E extends Extract<U, { type: T1 | T2 | T3 | T4 | T5 }>,
                              AC extends any,
                              T1 extends string | AC,
                              T2 extends string | AC,
                              T3 extends string | AC,
                              T4 extends string | AC,
                              T5 extends string | AC,
                              U extends any = any,
                              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
                              ): any;
                              <V extends any>(...allowedTypes: any[]): any;
                              };
                              • 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.

                              function ɵa

                              ɵa: <T>(instance: T) => EffectMetadata<T>[];

                                function ɵb

                                ɵb: (
                                injector: any,
                                effectGroups: Type<any>[][],
                                userProvidedEffectGroups: Type<any>[][]
                                ) => any[];

                                  function ɵc

                                  ɵc: (runner: EffectsRunner, rootEffects: any[][]) => any;

                                    Classes

                                    class Actions

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

                                      constructor

                                      constructor(source?: any);

                                        method lift

                                        lift: <R>(operator: any) => any;

                                          class EffectsFeatureModule

                                          class EffectsFeatureModule {}

                                            constructor

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

                                              class EffectsModule

                                              class EffectsModule {}

                                                method forFeature

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

                                                  method forRoot

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

                                                    class EffectSources

                                                    class EffectSources extends Subject<any> {}

                                                      constructor

                                                      constructor(errorHandler: any, effectsErrorHandler: EffectsErrorHandler);

                                                        method addEffects

                                                        addEffects: (effectSourceInstance: any) => void;

                                                          class EffectsRootModule

                                                          class EffectsRootModule {}

                                                            constructor

                                                            constructor(
                                                            sources: EffectSources,
                                                            runner: EffectsRunner,
                                                            store: any,
                                                            rootEffects: any[],
                                                            storeRootModule: any,
                                                            storeFeatureModule: any,
                                                            guard: any
                                                            );

                                                              method addEffects

                                                              addEffects: (effectSourceInstance: any) => void;

                                                                class EffectsRunner

                                                                class EffectsRunner implements OnDestroy {}

                                                                  constructor

                                                                  constructor(effectSources: EffectSources, store: any);

                                                                    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: () => any;
                                                                                        • 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$: any) => any;
                                                                                        • 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>