Цепные действия в эффекте ngrx v8 - PullRequest
0 голосов
/ 07 ноября 2019

Я хочу связать эффекты с последним синтаксисом ngrx. Я искал и нашел этот вопрос по stackoverflow, но он имеет старый синтаксис.

Это текущий эффект:

export class DeleteCommentEffect {

deleteComment$ = createEffect(() =>
    this.actions$.pipe(
        ofType(DeletingComment),
        mergeMap((action) => this.commentService.deleteComment(action.dossierId, action.commentId)
            .pipe(
                map((statusCode: number) => {
                    return DeleteCommentSuccess({ statusCode });
                }),
                catchError((error: HttpErrorResponse) => {
                    return of(DeleteCommentError({ error }));
                })
        ))
    )
);

constructor(
    private actions$: Actions,
    private commentService: DBCommentService) {
}

}

Я хочу связать этот эффект после успешного удаления комментария.

export class GetCommentEffects {
getComment$ = createEffect(() =>
    this.actions$.pipe(
        ofType(GettingComment),
        mergeMap(action =>
            this.commentService.getAllComments(action.dossierId).pipe(
                map((comments: Comment[]) => {
                    return GetCommentSuccess({comments});
                }),
                catchError((error: HttpErrorResponse) => {
                    return of(GetCommentError({error}));
                })
            ))
    )
);

constructor(
    private actions$: Actions,
    private commentService: DBCommentService
) {}

}

Я искал в ngrx docs , но, похоже, он не упоминает окак связать эффекты.

1 Ответ

1 голос
/ 07 ноября 2019

Создать эффект, который прослушивает DeleteCommentSuccess действие, которое отправляет GettingComment.

deleteCommentSuccess$ = createEffect(() =>
  this.actions$.pipe(
    ofType(DeleteCommentSuccess),
    map(() => CommentActions.GettingComments())
  )
);
...