X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Futils%2FcompgameStorage.js;h=c8463047fd5b1e07c6f49b302a9515f16baf7b2a;hb=HEAD;hp=e30a69fbeb853d68ca57eb02678bb7b27aa27e10;hpb=2c5d7b20742b802d9c47916915c1114bcfc9a9c3;p=vchess.git diff --git a/client/src/utils/compgameStorage.js b/client/src/utils/compgameStorage.js index e30a69fb..c8463047 100644 --- a/client/src/utils/compgameStorage.js +++ b/client/src/utils/compgameStorage.js @@ -37,8 +37,9 @@ function dbOperation(callback) { } export const CompgameStorage = { + add: function(game) { - dbOperation((err,db) => { + dbOperation((err, db) => { if (err) return; let objectStore = db .transaction("compgames", "readwrite") @@ -49,13 +50,13 @@ export const CompgameStorage = { // obj: move and/or fen update: function(gameId, obj) { - dbOperation((err,db) => { + dbOperation((err, db) => { let objectStore = db .transaction("compgames", "readwrite") .objectStore("compgames"); objectStore.get(gameId).onsuccess = function(event) { // Ignoring error silently: shouldn't happen now. TODO? - if (event.target.result) { + if (!!event.target.result) { const game = event.target.result; Object.keys(obj).forEach(k => { if (k == "move") game.moves.push(obj[k]); @@ -70,7 +71,7 @@ export const CompgameStorage = { // Retrieve any game from its identifier (variant name) // NOTE: need callback because result is obtained asynchronously get: function(gameId, callback) { - dbOperation((err,db) => { + dbOperation((err, db) => { let objectStore = db .transaction("compgames", "readonly") .objectStore("compgames"); @@ -82,7 +83,7 @@ export const CompgameStorage = { // Delete a game in indexedDB remove: function(gameId) { - dbOperation((err,db) => { + dbOperation((err, db) => { if (!err) { db.transaction("compgames", "readwrite") .objectStore("compgames") @@ -90,4 +91,5 @@ export const CompgameStorage = { } }); } + };