-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(effects): add OnIdentifyEffects interface to register multiple e…
…ffect instances (#1448) * feat(Effects): add OnIdentifyEffects interface * refactor(Effects): move OnRunEffects to lifecycle_hooks
- Loading branch information
1 parent
6a754aa
commit b553ce7
Showing
6 changed files
with
185 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { Observable } from 'rxjs'; | ||
import { EffectNotification } from '.'; | ||
|
||
/** | ||
* @description | ||
* 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. | ||
* | ||
* @usageNotes | ||
* | ||
* ### Set an identifier for an Effects class | ||
* | ||
* ```ts | ||
* class EffectWithIdentifier implements OnIdentifyEffects { | ||
* private effectIdentifier: string; | ||
* | ||
* ngrxOnIdentifyEffects () { | ||
* return this.effectIdentifier; | ||
* } | ||
* | ||
* constructor(identifier: string) { | ||
* this.effectIdentifier = identifier; | ||
* } | ||
* ``` | ||
*/ | ||
export interface OnIdentifyEffects { | ||
/** | ||
* @description | ||
* String identifier to differentiate effect instances. | ||
*/ | ||
ngrxOnIdentifyEffects: () => string; | ||
} | ||
|
||
export const onIdentifyEffectsKey: keyof OnIdentifyEffects = | ||
'ngrxOnIdentifyEffects'; | ||
|
||
export type onRunEffectsFn = ( | ||
resolvedEffects$: Observable<EffectNotification> | ||
) => Observable<EffectNotification>; | ||
|
||
/** | ||
* @description | ||
* 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. | ||
* | ||
* @usageNotes | ||
* | ||
* ### Implement the OnRunEffects interface on an Effects class | ||
* | ||
* ```ts | ||
* 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'))) | ||
* ) | ||
* ) | ||
* ); | ||
* } | ||
* } | ||
* ``` | ||
*/ | ||
export interface OnRunEffects { | ||
/** | ||
* @description | ||
* Method to control the lifecycle of effects. | ||
*/ | ||
ngrxOnRunEffects: onRunEffectsFn; | ||
} | ||
|
||
export const onRunEffectsKey: keyof OnRunEffects = 'ngrxOnRunEffects'; |
This file was deleted.
Oops, something went wrong.