Effect "AuthEffects.register$" 调度了一个无效的动作
Effect "AuthEffects.register$" dispatched an invalid action
我为注册操作添加了新效果,但出现此错误:效果 "AuthEffects.register$" 调度了无效操作
所以,这是我的效果:
@Effect()
register$ = this.actions$.pipe(
ofType<Register>(AuthActionTypes.Register),
map(action => action.payload),
exhaustMap((register: RegisterModel) =>
this.authService
.register(register)
.pipe(
tap(status => new RegisterSuccess(status)),
catchError(error => of(new RegisterFailure(error)))
)
)
);
这是 RegisterSuccess 操作:
export class RegisterSuccess implements Action {
readonly type = AuthActionTypes.RegisterSuccess;
constructor(public payload: boolean) {}
}
它 returns 一个布尔值,表示注册是否成功。
这是减速器案例:
case AuthActionTypes.RegisterSuccess: {
return {
...state,
error: null,
success: action.payload
}
}
问题出在哪里?效果看起来还可以,动作也可以,是不是我的reducer有问题?
谢谢!
您的 tap
应该是 map
才能 return 一个动作。
@Effect()
register$ = this.actions$.pipe(
ofType<Register>(AuthActionTypes.Register),
map(action => action.payload),
exhaustMap((register: RegisterModel) =>
this.authService
.register(register)
.pipe(
map(status => new RegisterSuccess(status)),
catchError(error => of(new RegisterFailure(error)))
)
)
);
我为注册操作添加了新效果,但出现此错误:效果 "AuthEffects.register$" 调度了无效操作
所以,这是我的效果:
@Effect()
register$ = this.actions$.pipe(
ofType<Register>(AuthActionTypes.Register),
map(action => action.payload),
exhaustMap((register: RegisterModel) =>
this.authService
.register(register)
.pipe(
tap(status => new RegisterSuccess(status)),
catchError(error => of(new RegisterFailure(error)))
)
)
);
这是 RegisterSuccess 操作:
export class RegisterSuccess implements Action {
readonly type = AuthActionTypes.RegisterSuccess;
constructor(public payload: boolean) {}
}
它 returns 一个布尔值,表示注册是否成功。 这是减速器案例:
case AuthActionTypes.RegisterSuccess: {
return {
...state,
error: null,
success: action.payload
}
}
问题出在哪里?效果看起来还可以,动作也可以,是不是我的reducer有问题? 谢谢!
您的 tap
应该是 map
才能 return 一个动作。
@Effect()
register$ = this.actions$.pipe(
ofType<Register>(AuthActionTypes.Register),
map(action => action.payload),
exhaustMap((register: RegisterModel) =>
this.authService
.register(register)
.pipe(
map(status => new RegisterSuccess(status)),
catchError(error => of(new RegisterFailure(error)))
)
)
);