From 82248ccbafc0cf06e64695654ae037541221f11f Mon Sep 17 00:00:00 2001 From: Jesse McDonald Date: Tue, 28 Apr 2020 23:12:10 -0500 Subject: [PATCH] add interfaces to retrieve cached data without a new request --- js/pacosako_io.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/js/pacosako_io.js b/js/pacosako_io.js index 585de5c..0049eb3 100644 --- a/js/pacosako_io.js +++ b/js/pacosako_io.js @@ -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) { if (Object.keys(meta.listeners).length === 0) { startMetaPoll(meta.lastModified); @@ -403,6 +415,8 @@ module.exports = { getGameMeta, onGameUpdate, onMetaUpdate, + getCachedGame, + getCachedMeta, sendUpdate, getConnectionState, onConnectionStateChanged,