X-Git-Url: https://git.auder.net/images/pieces/current/gitweb.js?a=blobdiff_plain;f=client%2Fsrc%2Futils%2FgameStorage.js;h=129866798b63e865e11601bde3364e84abcb05a3;hb=478315ed4fbbfa96959b108efb634efb444aa424;hp=92db29915abf33081e61e6571c07f368ae72e9ae;hpb=3b0f26c1261db7ea06067762c0c28b6dbacf2d99;p=vchess.git diff --git a/client/src/utils/gameStorage.js b/client/src/utils/gameStorage.js index 92db2991..12986679 100644 --- a/client/src/utils/gameStorage.js +++ b/client/src/utils/gameStorage.js @@ -43,7 +43,7 @@ export const GameStorage = { // Optional callback to get error status add: function(game, callback) { dbOperation((err,db) => { - if (err) { + if (!!err) { callback("error"); return; } @@ -51,6 +51,9 @@ export const GameStorage = { transaction.oncomplete = function() { callback(); //everything's fine }; + transaction.onerror = function(err) { + callback(err); //duplicate key error (most likely) + }; let objectStore = transaction.objectStore("games"); objectStore.add(game); }); @@ -80,8 +83,7 @@ export const GameStorage = { }, // Retrieve all local games (running, completed, imported...) - // light: do not retrieve moves or clocks (TODO: this is the only usage) - getAll: function(light, callback) { + getAll: function(callback) { dbOperation((err,db) => { let objectStore = db.transaction("games").objectStore("games"); let games = []; @@ -90,12 +92,11 @@ export const GameStorage = { // if there is still another cursor to go, keep running this code if (cursor) { let g = cursor.value; - if (light) { - g.movesCount = g.moves.length; - delete g.moves; - delete g.clocks; - delete g.initime; - } + // Do not retrieve moves or clocks (unused in list mode) + g.movesCount = g.moves.length; + delete g.moves; + delete g.clocks; + delete g.initime; games.push(g); cursor.continue(); } else callback(games); @@ -110,8 +111,8 @@ export const GameStorage = { dbOperation((err,db) => { let objectStore = db.transaction("games").objectStore("games"); objectStore.get(gameId).onsuccess = function(event) { - if (event.target.result) - callback(event.target.result); + // event.target.result is null if game not found + callback(event.target.result); }; }); },