简体   繁体   English

如何使用两个concatMap?

[英]How to use two concatMap?

I have the following code:我有以下代码:

event.afterClosed()
  .pipe((filter(Boolean), 
         concatMap(() => this.applicationSubjectsService.get(this.id),
         concatMap(() => this.applicationThemesService.get(this.id)
    )))

I would execute two sequence requests.我会执行两个序列请求。 How to get result from each and add to local variable?如何从每个获取结果并添加到局部变量?

I have tried this:我试过这个:

event.afterClosed()
  .pipe((filter(Boolean), 
         concatMap(() => this.applicationSubjectsService.get(this.id), finilize((response) =>  this.localSubjects = response),
         concatMap(() => this.applicationThemesService.get(this.id),
         finilize((response) =>  this.localThemes = response),
    )))

How to do that correctly and what should I change if I need execute at least one request?如何正确地做到这一点,如果我需要执行至少一个请求,我应该改变什么?

You should be able to use the tap operator to hook into the result from the switchMap.您应该能够使用点击运算符挂钩到 switchMap 的结果。 You can read about the tap operator here: tap您可以在此处阅读有关 tap 运算符的信息: tap

event.afterClosed()
   .pipe((filter(Boolean), 
       concatMap(() => this.applicationSubjectsService.get(this.id)),
       tap((result) => this.localSubjects = result),
       concatMap(() => this.applicationThemesService.get(this.id)),
       tap((result) => this.localThemes = result))
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM