X-Git-Url: https://git.auder.net/?a=blobdiff_plain;ds=sidebyside;f=client%2Fsrc%2Futils%2FgameStorage.js;h=480c73baef65a958676481b72ded2afd7c29a204;hb=620a88ede2ad25e66d9cbb521388ee53e4a564c0;hp=ce609af09ad8fdcc1fe93e1fa88d47930490d979;hpb=98b94cc3504937ae0af29a265394dfe52ea1ee67;p=vchess.git diff --git a/client/src/utils/gameStorage.js b/client/src/utils/gameStorage.js index ce609af0..480c73ba 100644 --- a/client/src/utils/gameStorage.js +++ b/client/src/utils/gameStorage.js @@ -83,7 +83,9 @@ 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; + // Hidden tabs are delayed, to prevent multi-updates: + if (obj.moveIdx < game.moves.length) return; Object.keys(obj).forEach(k => { if (k == "move") game.moves.push(obj[k]); else game[k] = obj[k]; @@ -96,7 +98,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 = []; @@ -104,7 +107,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); };