I would like to transform below code snippet:
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
}));
});
}
});
by avoid nested subscription. All examples, which I found, is per two subscriptions.
this.dataUserSubscription = this.store$.pipe(select(selectUser),
switchMap(user => this.store$.pipe(select(selectUserData, {user}))))
.subscription(userData => {
// logic
})
But it is no proper solution for my example of code. Why is the proper step for fixing multiple nested subscriptions?