Reputation: 663
Here an example:
Is this approach correct? Should I unsubscribe in each switchMap? Should I call takeUntil after each switchMap?
this.sharedSrv.postDetail.pipe(
switchMap(post => {
if (post) {
this.hasPost = true;
this.post = post;
}
this.viewedMainComment = null;
this.viewedSubComments = [];
return this.userSrv.getUserAsObservable();
}),
takeUntil(this.destroyFirstSwitchMap$),
switchMap(user => {
if (user) {
if (this.post.user.id == user.id) this.isOwnPost = true;
this.user = user;
console.log(user);
return this.postsSrv.getPostInteraction(this.user.id, this.post.id, this.post.user.id);
}
return of(null);
}),
takeUntil(this.destroySecondSwitchMap$),
).subscribe( );
Upvotes: 1
Views: 302
Reputation: 54599
Yes, one takeUntil will end all subscriptions in cascade.
Upvotes: 1