I tried to make the following stream work, with map and flatMap, however it does what it should do, but the code is not optimal e.g the second time I am using flatMap, I never read it's response value, but I just don't know how to continue the flow without, and if I remove it I get an error
Argument of type 'Observable' is not assignable to parameter of type '(outerValue: any, innerValue: void, outerIndex: number, innerIndex: number) => any'
So how can I make this better ?
person;
facility;
apiUrl1: string = 'http://localhost:3000/person/?';
apiUrl2: string = 'http://localhost:3000/facility/?';
apiUrl3: string = 'http://localhost:3000/exposure/?';
constructor(private http: HttpClient) { }
getData(arg): Observable<any> {
return this.http.get(this.apiUrl1 + arg.data)
.map((response: any) =>
this.person = response
)
.flatMap((response: any) => this.http.get(this.apiUrl2 + response.val1)
.map((response: any) => {
this.facility = response
})
.flatMap((response: any) => this.http.get(this.apiUrl3 + this.person.val2)
.map((response: any) => response.val5 * this.facility.val3)))
}
}
flatMapyou never use theresponseargument, then you can use the following syntax() => this.http.get(this.apiUrl3 + this.person.val2). You need to useflatMapsince you are calling againhttp.getwhich returns an Observableanyeverywhere, but instead used proper types, the compiler would catch those errors for you. any is evil. Don't use any.