Skip to content

Instantly share code, notes, and snippets.

@pbabbott
Last active January 24, 2018 04:53
Show Gist options
  • Save pbabbott/edcb69dddd8468b077c447144cb1127d to your computer and use it in GitHub Desktop.
Save pbabbott/edcb69dddd8468b077c447144cb1127d to your computer and use it in GitHub Desktop.
import apiClient from 'somewhere-else';
const pokemonCache = {};
export function getRawPokemonData(id){
let cachedPokemon = pokemonCache[id];
if (cachedPokemon){
return new Promise((resolve, reject) =>{
resolve(cachedPokemon);
});
} else{
return apiClient.get('/pokemon/' + id).then(r => {
pokemonCache[id] = r.data;
return r.data;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment