add interfaces to retrieve cached data without a new request

This commit is contained in:
Jesse D. McDonald 2020-04-28 23:12:10 -05:00
parent 3f173d70a2
commit 82248ccbaf
1 changed files with 14 additions and 0 deletions

View File

@ -106,6 +106,18 @@ function onGameUpdate(gameId, callback) {
} }
} }
function getCachedGame(gameId) {
if (gameId in games) {
return JSON.stringify(games[gameId].data);
} else {
return undefined;
}
}
function getCachedMeta() {
return JSON.parse(JSON.stringify(meta.games));
}
function onMetaUpdate(callback) { function onMetaUpdate(callback) {
if (Object.keys(meta.listeners).length === 0) { if (Object.keys(meta.listeners).length === 0) {
startMetaPoll(meta.lastModified); startMetaPoll(meta.lastModified);
@ -403,6 +415,8 @@ module.exports = {
getGameMeta, getGameMeta,
onGameUpdate, onGameUpdate,
onMetaUpdate, onMetaUpdate,
getCachedGame,
getCachedMeta,
sendUpdate, sendUpdate,
getConnectionState, getConnectionState,
onConnectionStateChanged, onConnectionStateChanged,