多个switchmap,我应该退订吗?
这里一个例子:
这种方法正确吗? 我应该在每个 switchmap 中退订吗?我应该在每个 switchmap 之后打电话 takeuntil 吗?
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( );
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( );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,一个Takeuntil将结束级联中的所有订阅。
Yes, one takeUntil will end all subscriptions in cascade.