Code: Select all
// this will make API call for chain everytime lastLoadedscript is set
myResource = rxResource({
request: () => {
let script = this.stateService.lastLoadedScript()
let tempReq = {
seg: script.id || 0,
sid: script.sid
}
return tempReq
},
loader: ({ request }) => {
return this.myService.getExplist(request).pipe(
switchMap((expiryDetails: ExpiryDetails[]) => {
this.expiryList = expiryDetails;
this.expirySortname = this.expiryList.map(e => e.sortname);
let script = this.stateService.lastLoadedScript();
let tempObj = {
"StrategyName": "*",
"Symbol": script.name,
"ExpiryJulian": this.expiryList[this.prebuiltExpiry()].expiry
};
return this.myService.getstrategy(tempObj).pipe(
map(resp => {
if (resp['status'] != 'success') {
throw new Error('Invalid resp');
}
return processData(resp['data'])
})
);
})
);
}
})
Ziel ist
- Auf der Seite laden Sie den Aufruf explist, sobald die Antwort kam, rufen Sie getStrategy auf
- Führen Sie alle nachfolgenden Aufrufe von getstrategy mit einfachem myResource.reload() mit ausgewähltem Ablauf aus, aber erstellen Sie keine Ablauf-API call.
- Wenn sich lastLoadedScript ändert, wiederholen Sie Schritt 1. d. h.: Rufen Sie exp auf und rufen Sie dann get strategy auf