我有一种情况,其中调用了效果,但是未访问基础服务。是什么原因造成的?
user.effect.ts
@Effect()
getData$ = this.actions$.pipe(
ofType(UserActions.getData),
switchMap(() =>
this.userService.getUserById(localStorage.getItem("uid")).pipe(
map((data: IUser) => {
if (data) {
return UserActions.dataReceived({
payload: UserService.parseData(data)
});
} else {
return UserActions.dataNotReceived();
}
}),
catchError(err =>
of(
AuthActions.signOutError({
errorMessage: err.message,
errorCode: err.code
})
)
)
)
)
);
user.service.ts
getUserById(id) {
this.logger.debug(`Getting user ${id}`);
return this.afs
.collection("users")
.doc(id)
.snapshotChanges()
.pipe(
map(action => {
const data = action.payload.data();
const uid = action.payload.id;
return { uid, ...data };
})
);
}
答案 0 :(得分:1)
您应该使用return new不返回。像这样
if (data) {
return new UserActions.dataReceived({
payload: UserService.parseData(data)
});
} else {
return new UserActions.dataNotReceived();
}