When attempting to examine values between operators in an rxjs pipe, I decided to use tap to log them to the console.
I added two taps, one before a map operator used for sorting an Array, and one after. Surprisingly, both taps logged the same sorted Array, instead of displaying the original order followed by the sorted one.
This indicates that the sorting done in the map operator impacts the observable used by the preceding tap operator. However, the operators' functions appear to execute sequentially as expected, since the log from the second map is displayed between the taps' logs.
Here is my code (I plan to specify the Observable Array's type properly later):
public getJSONData(): Observable<any[]> {
return this.http.get(this.poisJSONPath).pipe(
map((featureCollection: any) => featureCollection.features),
tap((features) => console.log(features)),
map((features: any) => {
console.log('this is logged in between as expected');
return features.sort((a, b) =>
a.properties.name > b.properties.name ? 1 : -1
);
}),
tap((features) => console.log(features))
);
}
I suspect there may be a critical aspect of how rxjs pipes operate that I'm overlooking. In every other example I've seen, tap behaves as I anticipate. Can anyone point out what I might be missing?