【发布时间】:2020-01-20 10:20:50
【问题描述】:
所以我们有这个普通的效果doSomething。 官方发送另一个名为doSomethingElse的操作的方式是什么?该文档并没有真正说明正确的方法。最后可能没有太大区别,但我不太喜欢我可以在 95% 的代码库中使用 dispatch: false。
使用dispatch: false 调度操作:
doSomething$ = createEffect(() =>
this.actions$.pipe(
ofType(AuthActions.doSomething),
map(() => AuthActions.doSomethingElse())
));
doSomethingElse$ = createEffect(
() =>
this.actions$.pipe(
ofType(AuthActions.doSomethingElse),
tap(() => console.log('it works!'))
),
{ dispatch: false });
没有dispatch: false的调度动作:
doSomething$ = createEffect(
() =>
this.actions$.pipe(
ofType(AuthActions.doSomething),
tap(() => {
this.store.dispatch(AuthActions.doSomethingElse());
})
),
{ dispatch: false });
doSomethingElse$ = createEffect(
() =>
this.actions$.pipe(
ofType(AuthActions.doSomethingElse),
tap(() => console.log('it works!'))
),
{ dispatch: false });
两种解决方案都有效,但我不确定哪种是使用 NgRx 的正确方法。
【问题讨论】: