【发布时间】:2019-01-13 23:49:17
【问题描述】:
你能告诉我什么是派发动作的正确方法吗?
在组件中,我们确实喜欢使用store 使用store.dispatch 而不是操作。
onLoginButtonClick(user: Authenticate) {
this.store.dispatch(new Authctions.Login(user));
}
现在使用ngEffect 我们调度动作而不使用store 只使用new Action name 为什么?
export class AuthEffect {
@Effect()
login$ = this.actions$.pipe(
ofType(AuthActionsTypes.LOGIN),
map((action: Login) => action.payload),
switchMap((auth: Authenticate) => {
return this.authService.login(auth).pipe(
map(user => new LoginSuccess({user})),
catchError(error => of(new LoginFailure(error)))
);
})
);
为什么会这样使用
new LoginSuccess({user})
我们可以这样使用this.store.dispatch( new LoginSuccess({user})) 吗?有效吗?
有什么更新吗?
【问题讨论】:
标签: angular ngrx effects ngrx-store ngrx-effects