Skip to content

Best practices for generic effects #3428

Answered by david-shortman
MikelEiza asked this question in Q&A
Discussion options

You must be logged in to vote

I recommend following an "action metadata" pattern to drive side-effects like showing notifications.

Please check out my article here: https://dev.to/davidshortman/describe-your-ngrx-actions-more-to-write-less-code-1fij

In your instance, you could insert metadata like so:

export const productsLoadedFailure = createAction(
    '[Home Page] Products loaded failure',
    (payload: { error: { message: string } }) => ({
        ...payload,
        notificationMetadata: { message }
    })
);

Then you could generically react to actions with notification metadata:

showErrorToast$ = createEffect(() =>
    this.actions$.pipe(
        filter(hasNotificationMetadata),
        tap(({ notificationMetadata

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
3 replies
@MikelEiza
Comment options

@david-shortman
Comment options

@MikelEiza
Comment options

Answer selected by MikelEiza
Comment options

You must be logged in to vote
2 replies
@MikelEiza
Comment options

@Armenvardanyan95
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants