我想转换下面的代码片段:
this.dataUserSubscription = this.store$.pipe(select(selectUser)).subscribe(
user => {
this.store$.pipe(select(selectUserData, {user}), take(1))
.subscribe(userData => {
if (userData === null) {
this.store$.pipe(select(selectUserManagement, {user}), take(1)).subscribe(
userManagement => {
this.store$.dispatch(saveUserDataToStore({
user,
userManagement
}));
});
}
});
通过避免嵌套订阅。我发现的所有示例都是按两次订阅计算的。
this.dataUserSubscription = this.store$.pipe(select(selectUser),
switchMap(user => this.store$.pipe(select(selectUserData, {user}))))
.subscription(userData => {
// logic
})
但这不是我的代码示例的正确解决方案。为什么修复多个嵌套订阅是正确的步骤?