问题
You can see I have a method , which is working fine as I expected
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;
});
}
}
Execution
- getTheConfiguration() => basedontheconfigresponse=>
- calling getTemplate(basedontheconfigresponse)=>basedntheTemplateresponse=>
- calling getAllChildTemplates(basedntheTemplateresponse )=> basedonthechildtemplateresponse=>
- calling createTemplate(basedonthechildtemplateresponse,"")
in the 4 bullet point I passing an empty parameter to the createTemplate method , actually I have to pass basedntheTemplateresponse(in code rootTemplate). Right now I am doing a tweak by setting up when execute getAllChildTemplates
getAllChildTemplates(parentTemplate: string) {
this.currentrootTemplate = parentTemplate;
var services = this.getChildTemplateServiceInstance(parentTemplate);
return forkJoin(services);
}
is there any right way to pass the rootTemplate from the pipe itself to the next concatMap ? I am not sure is this is the right approach.
回答1:
You can just map the result from the inner Observable into an array of the current response and the previous one:
concatMap(rootTemplate =>
this.templateEngine.getAllChildTemplates(rootTemplate).pipe(
map(childTemplates => [rootTemplate, childTemplates])
)
),
concatMap(([rootTemplate, childTemplates]) =>
this.templateEngine.createTemplateToRender(childTemplates, rootTemplate)
)
来源:https://stackoverflow.com/questions/52953654/passing-concatmap-result-in-to-next-concatmap-in-rxjs