I have the following piece of code:
public getDomains(): Observable<any[]> {
const customer = this.storage.getCustomer();
const apiUrl= this.configuration.getApiUrl(customer);
return this.http.get((`${apiUrl}/domains`).toLowerCase())
.map((response) => response.json() || []);
}
const domains = this.myService.getDomains().
.shareReplay()
.concatMap((domains) => domains.map((domain) => this.toDomainModel(domain, myObservable)))
.filter((domain) => this.isValidDomain(domain))
.toArray();
My network tab is showing the response from the request as an array with 3 items in it. But somehow, even after removing everything and only leaving the .toArray()
, it is transformed into an Array with 3 elements, where each element itself is an Array of 3 items. The network response is being duplicated 4 times somewhere.
I call a service method which returns an array of items which I then send through this chain of methods. For some reason, and I believe it may have to do with concatMap
, I end up with more items than the endpoint originally returned.
I should get 3 items back from the request, and then the filter should remove 2 of those so I should be left with one. I'm fairly new to rxjs
and am curious as to whether or not this is common behavior with concatMap
.
Any ideas? Thanks