X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Futils%2FgameStorage.js;h=2e78994286cbb19cdb795b8ca6880e6b04cd92f5;hb=dcff8e82dd8bbc285d9c2d5d5e3b361a9ecfa9ac;hp=cc7dca5b78a9539205be6ccae7dc9db902a16559;hpb=8477e53d8e78606e4c4e4bf91c77b1011aab583c;p=vchess.git diff --git a/client/src/utils/gameStorage.js b/client/src/utils/gameStorage.js index cc7dca5b..2e789942 100644 --- a/client/src/utils/gameStorage.js +++ b/client/src/utils/gameStorage.js @@ -7,7 +7,6 @@ // cadence: string, // increment: integer (seconds), // type: string ("live" or "corr") -// imported: boolean (optional, default false) // // Game (dynamic) state: // fen: string, // moves: array of Move objects, @@ -84,7 +83,7 @@ export const GameStorage = { objectStore.get(gameId).onsuccess = function(event) { // Ignoring error silently: shouldn't happen now. TODO? if (event.target.result) { - const game = event.target.result; + let game = event.target.result; Object.keys(obj).forEach(k => { if (k == "move") game.moves.push(obj[k]); else game[k] = obj[k]; @@ -97,7 +96,8 @@ export const GameStorage = { }, // Retrieve all local games (running, completed, imported...) - getAll: function(callback) { + // light: do not retrieve moves or clocks (TODO: this is the only usage) + getAll: function(light, callback) { dbOperation((err,db) => { let objectStore = db.transaction("games").objectStore("games"); let games = []; @@ -105,7 +105,14 @@ export const GameStorage = { let cursor = event.target.result; // if there is still another cursor to go, keep running this code if (cursor) { - games.push(cursor.value); + let g = cursor.value; + if (light) { + g.movesCount = g.moves.length; + delete g.moves; + delete g.clocks; + delete g.initime; + } + games.push(g); cursor.continue(); } else callback(games); };