UNPKG

3.01 kBTypeScriptView Raw
1import { Observable } from 'rxjs';
2import { EffectNotification } from '.';
3import { Action } from '@ngrx/store';
4/**
5 * @description
6 * Interface to set an identifier for effect instances.
7 *
8 * By default, each Effects class is registered
9 * once regardless of how many times the Effect class
10 * is loaded. By implementing this interface, you define
11 * a unique identifier to register an Effects class instance
12 * multiple times.
13 *
14 * @usageNotes
15 *
16 * ### Set an identifier for an Effects class
17 *
18 * ```ts
19 * class EffectWithIdentifier implements OnIdentifyEffects {
20 * constructor(private effectIdentifier: string) {}
21 *
22 * ngrxOnIdentifyEffects() {
23 * return this.effectIdentifier;
24 * }
25 *
26 * ```
27 */
28export declare interface OnIdentifyEffects {
29 /**
30 * @description
31 * String identifier to differentiate effect instances.
32 */
33 ngrxOnIdentifyEffects(): string;
34}
35export declare const onIdentifyEffectsKey: keyof OnIdentifyEffects;
36export declare function isOnIdentifyEffects(instance: any): instance is OnIdentifyEffects;
37/**
38 * @description
39 * Interface to control the lifecycle of effects.
40 *
41 * By default, effects are merged and subscribed to the store. Implement the OnRunEffects interface to control the lifecycle of the resolved effects.
42 *
43 * @usageNotes
44 *
45 * ### Implement the OnRunEffects interface on an Effects class
46 *
47 * ```ts
48 * export class UserEffects implements OnRunEffects {
49 * constructor(private actions$: Actions) {}
50 *
51 * ngrxOnRunEffects(resolvedEffects$: Observable<EffectNotification>) {
52 * return this.actions$.pipe(
53 * ofType('LOGGED_IN'),
54 * exhaustMap(() =>
55 * resolvedEffects$.pipe(
56 * takeUntil(this.actions$.pipe(ofType('LOGGED_OUT')))
57 * )
58 * )
59 * );
60 * }
61 * }
62 * ```
63 */
64export declare interface OnRunEffects {
65 /**
66 * @description
67 * Method to control the lifecycle of effects.
68 */
69 ngrxOnRunEffects(resolvedEffects$: Observable<EffectNotification>): Observable<EffectNotification>;
70}
71export declare const onRunEffectsKey: keyof OnRunEffects;
72export declare function isOnRunEffects(instance: any): instance is OnRunEffects;
73/**
74 * @description
75 * Interface to dispatch an action after effect registration.
76 *
77 * Implement this interface to dispatch a custom action after
78 * the effect has been added. You can listen to this action
79 * in the rest of the application to execute something after
80 * the effect is registered.
81 *
82 * @usageNotes
83 *
84 * ### Set an identifier for an Effects class
85 *
86 * ```ts
87 * class EffectWithInitAction implements OnInitEffects {
88 * ngrxOnInitEffects() {
89 * return { type: '[EffectWithInitAction] Init' };
90 * }
91 * ```
92 */
93export declare interface OnInitEffects {
94 /**
95 * @description
96 * Action to be dispatched after the effect is registered.
97 */
98 ngrxOnInitEffects(): Action;
99}
100export declare const onInitEffects: keyof OnInitEffects;
101export declare function isOnInitEffects(instance: any): instance is OnInitEffects;