In Angular I would prevent duplicate requests with RxJS shareReplay
like this:
const items: Observable<Item[]> =
httpClient.get("http://some.where").pipe(shareReplay(1))
const names: Observable<String[]> = items.pipe(map(item => item.names))
As you can see there is the items
Observable
which represents the HTTP response, and a second observable, names
, which is a projection of the first. Obviously it would be wasteful to perform the HTTP request twice (what could even lead to inconsistencies in this case). Therefore the HTTP response gets multicasted by shareReplay(1)
.
How would the same be implemented with Flow?