Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Last active March 23, 2020 20:14
Show Gist options
  • Save NyaGarcia/4fbed562a24ba71b13e648fec80c0554 to your computer and use it in GitHub Desktop.
Save NyaGarcia/4fbed562a24ba71b13e648fec80c0554 to your computer and use it in GitHub Desktop.
Duplicating http request with cold observables
pokemon$ = http.get(/* make an http request here*/);
/*Every time we subscribe to pokemon$, an http request will be made*/
pokemon$
.pipe(
flatMap(pokemon => pokemon),
filter(({ type }) => type === "Fire")
)
.subscribe(pokemon => {
// Do something with pokemon
});
pokemon$.pipe(switchMap(pokemon => getStats(pokemon))).subscribe(stats => {
// Do something with stats
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment