下面是一个例子:
这个方法正确吗?我应该取消订阅吗switchMap? 我是否应该调用takeUntil在每个之后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( );
是的,一次takeUntil将级联结束所有订阅。