I am looking to revamp the code snippet below:
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
}));
});
}
});
I am seeking a solution that eliminates nested subscriptions. Most examples I've come across involve just two subscriptions.
this.dataUserSubscription = this.store$.pipe(select(selectUser),
switchMap(user => this.store$.pipe(select(selectUserData, {user}))))
.subscription(userData => {
// logic
})
The above solution does not fit my specific scenario. What is the right approach for removing multiple nested subscriptions in this case?