Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Created July 15, 2020 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NyaGarcia/b8579b9b8ae2cbb2f47e567b90b12ce4 to your computer and use it in GitHub Desktop.
Save NyaGarcia/b8579b9b8ae2cbb2f47e567b90b12ce4 to your computer and use it in GitHub Desktop.
import { mergeAll, map, delay } from 'rxjs/operators';
import { ajax } from 'rxjs/ajax';
import { of } from 'rxjs';
const pokemonId$ = of(1, 5, 6);
function getPokemonName(id: number) {
return ajax.getJSON(`https://pokeapi.co/api/v2/pokemon/${id}`).pipe(
map(({ name }) => name),
delay(2000)
);
}
pokemonId$
.pipe(
concatMap(id => getPokemonName(id))
)
.subscribe(console.log);
// Output: (2s) bulbasaur, charmeleon, charizard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment