Last active
March 23, 2020 20:14
-
-
Save NyaGarcia/4fbed562a24ba71b13e648fec80c0554 to your computer and use it in GitHub Desktop.
Duplicating http request with cold observables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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