I know already there are posts regarding the Nested Subscribe. Here, we have 5 leveled subscribeoperation with each variables (operationId,actionlistId,componentId,traceId). Her
Your code looks correct. So you need to figure out what part of code gets so many time. I suggest you to use performance.now() method to measure your code:
console.log(`1. performance.now() ${performance.now()}`);
this.ordertemplateService.GetOperationTemplate(this.orderTemplateId)
.pipe(
switchMap((opData)=> {
console.log(`2. performance.now() ${performance.now()}`);
}),
switchMap((actData)=> {
console.log('ActionList');
switchMap((cmpData)=> {
console.log(`3. performance.now() ${performance.now()}`);
this.componentModel = this.ordertemplateService.GetComponentUsageTemplate(this.actionModel[0].id); // cmpData[0].id
this.componentId = this.componentModel[0].id;
if (Object.keys(this.componentModel).length > 0) {
console.log(this.componentModel);
console.log('Component Usage');
} else {
this.initializeComponentTrace();
}
console.log(`4. performance.now() ${performance.now()}`);
}),
switchMap((traceData)=> {
console.log(`5. performance.now() ${performance.now()}`);
this.traceModel = this.ordertemplateService.GetTraceTemplate(this.componentModel[0].parentId); // cmpData[0].id
if (Object.keys(this.traceModel).length > 0) {
this.traceId = this.traceModel[0].id;
console.log(this.traceModel);
console.log('Trace Usage')
} else {
this.initializeTrace();
}
console.log(`6. performance.now() ${performance.now()}`);
}))
.subscribe((data)=> {
if(data!= undefined) {
console.log(data);
console.log(`7. performance.now() ${performance.now()}`);
}
})
Then you will have an iformation, what piece of code is takes so many time.