Here I've done the RxJS thing of not putting any side effects into your transformations/data pipeline and saving them all for the end consumer (subscribe).
This should make it much easier to test, extend, and maintain your code.
Typically your end consumer should be the UI or a database of some sort. There's rarely a reason to have your end consumer just set a global variable, but that's where I left it for now.
this.http.get<IFilm>(`https://swapi.dev/api/films/${id}/`).pipe(
map(film => ({
film,
nameCalls: film.characters.map(
url => this.http.get<IActor>(url)
)
})),
mergeMap(({film, nameCalls}) => forkJoin(nameCalls).pipe(
map(names => ({film, names}))
))
).subscribe(({film, names}) => {
this.film = film;
this.nameList = names;
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…