At this moment, I am using the following code for the operation mentioned in the title:
from(["url_1", "url_2"])
.pipe(
concatMap(url => this.vocabularyService.getSimilarProducts(url)
.pipe(concatMap(x => x.items))
),
toArray()
)
.subscribe(res => console.log(res));
This code works by making an API call for each URL in the array of URLs, returning a response similar to this:
class Response {
items: Object[]
}
Upon receiving the response, another concatMap()
is used to retrieve each item in the items array and ultimately flattening them into a single array with toArray()
, finally logging it into the console.
I'm curious if RxJs provides any specific operator for handling this process more efficiently, perhaps without the need for multiple nested concatMap()
operators?