效果ngrx v8中的连锁动作

时间:2019-11-07 13:32:21

标签: ngrx-effects

我想用最新的ngrx语法链接效果。我搜索并发现了this个关于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 个答案:

答案 0 :(得分:1)

创建一个效果,以监听分派DeleteCommentSuccess的{​​{1}}动作。

GettingComment