Last active
August 6, 2019 15:48
-
-
Save dkblay/899a61fd06ea128e51266bb3f7e9edf8 to your computer and use it in GitHub Desktop.
api
This file contains 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
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