передача результата concatMap к следующему concatMap в rxjs - PullRequest
0 голосов
/ 23 октября 2018

Вы видите, что у меня есть метод, который работает нормально, как я ожидал

loadTemplates(configUrl: any, templateId: string): Observable<any> {
    this.getConfiguration(configUrl)
      .pipe(

        concatMap(configResponse =>
          this.getTemplate(
            CONFIGURATION_URL +
              "templates/" +
              configResponse.TemplateSettings.RootTemplate.Path,
            configResponse
          )
        ),
        concatMap(rootTemplate =>
          this.templateEngine.getAllChildTemplates(rootTemplate)       
        ),
        concatMap(childTemplates=>this.templateEngine.createTemplateToRender(childTemplates,""))
      )
      .subscribe(finalresponse=> {

        debugger;
      });

  }
}

Выполнение

  1. getTheConfiguration () => basedontheconfigresponse =>
  2. вызов getTemplate (basedontheconfigresponse) => basedntheTemplateresponse =>
  3. вызов getAllChildTemplates (basedntheTemplateresponse) => basedonthechildtemplateresponse =>
  4. вызов createTemplate (basedonthe)

в 4-й маркерной точке я передаю пустой параметр методу createTemplate , на самом деле мне нужно передать basedntheTemplateresponse (в коде rootTemplate ),Прямо сейчас я делаю твик, настраивая при выполнении getAllChildTemplates

getAllChildTemplates(parentTemplate: string) {
    this.currentrootTemplate = parentTemplate;
    var services = this.getChildTemplateServiceInstance(parentTemplate);
    return forkJoin(services);
  }

, есть ли какой-нибудь правильный способ передать rootTemplate от самого канала к следующему concatMap ?Я не уверен, что это правильный подход.

1 Ответ

0 голосов
/ 23 октября 2018

Вы можете просто отобразить результат из внутреннего Observable в массив текущего ответа и предыдущего:

concatMap(rootTemplate =>
  this.templateEngine.getAllChildTemplates(rootTemplate).pipe(
    map(childTemplates => [rootTemplate, childTemplates])
  )
),
concatMap(([rootTemplate, childTemplates]) => 
  this.templateEngine.createTemplateToRender(childTemplates, rootTemplate)
)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...