Skip to content

Instantly share code, notes, and snippets.

@dkblay
Last active August 6, 2019 15:48
Show Gist options
  • Save dkblay/899a61fd06ea128e51266bb3f7e9edf8 to your computer and use it in GitHub Desktop.
Save dkblay/899a61fd06ea128e51266bb3f7e9edf8 to your computer and use it in GitHub Desktop.
api
import Game from "../model/Game";
export async function getGames({ page, size }) {
const start = page * size - size;
const end = start + size;
const data = await gamesData;
return {
games: data.slice(start, end),
total: data.length
};
}
async function loadData() {
try {
const data = await (await fetch("/data/test.json")).json();
return data.map(game => new Game(game));
} catch (e) {
console.error(e);
}
}
/* This is to ensure that a one time call is made for the games data */
const gamesData = loadData();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment