X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Futils%2FcompgameStorage.js;h=c8463047fd5b1e07c6f49b302a9515f16baf7b2a;hb=937c24ab2871b31a7e531226603fc75acab7edb8;hp=a8bcaa2a7f02b6004c21c4d0bc95574b575ab142;hpb=bee36510477b04dee500a9a624584544b9c8bdb2;p=vchess.git diff --git a/client/src/utils/compgameStorage.js b/client/src/utils/compgameStorage.js index a8bcaa2a..c8463047 100644 --- a/client/src/utils/compgameStorage.js +++ b/client/src/utils/compgameStorage.js @@ -15,7 +15,8 @@ function dbOperation(callback) { let DBOpenRequest = window.indexedDB.open("vchess_comp", 4); DBOpenRequest.onerror = function(event) { - alert(store.state.tr["Database error: stop private browsing, or update your browser"]); + alert(store.state.tr[ + "Database error: stop private browsing, or update your browser"]); callback("error", null); }; @@ -36,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") @@ -48,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]); @@ -69,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"); @@ -81,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") @@ -89,4 +91,5 @@ export const CompgameStorage = { } }); } + };