【发布时间】:2020-06-11 01:45:25
【问题描述】:
我有下面的选择器
export const selectUserData = createSelector(selectState, state => {
return state.user;
});
在我看来,如果我使用 withLatestFrom 而不使用 []
withLatestFrom(
this.commonStore.pipe(select(selectUserData))
)
loadUser$ = createEffect(() =>
this.actions$.pipe(
ofType(UserActionsTypes.GetUserSuccess),
withLatestFrom(
this.commonStore.pipe(select(selectUserData))
),
mergeMap(([_, user]) => {
console.log(user);
}
console.log 将返回空数据
但是如果我将 [] 添加到 withLatestFrom
withLatestFrom(
[this.commonStore.pipe(select(selectUserData))]
)
然后我会在mergeMap中使用subscribe来获取数据
console.log(user.subscribe(x => console.log(x)));
请注意,选择器有数据,我在 redux devtool 中检查数据是否存在。
知道它是怎么发生的吗?
【问题讨论】:
-
@AndrewAllen 谢谢我试过了,但它不适用于我的情况
-
一切正常。尝试调试
return state.user以查看它返回的内容 - 可能是null是您在我们看不到的应用程序的其他部分中流动的正确原因
标签: angular typescript redux rxjs ngrx