projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Improve Chakart computer play
[vchess.git]
/
client
/
src
/
utils
/
compgameStorage.js
diff --git
a/client/src/utils/compgameStorage.js
b/client/src/utils/compgameStorage.js
index
a5c58af
..
4f5181e
100644
(file)
--- 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) {
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);
};
callback("error", null);
};
@@
-27,13
+28,17
@@
function dbOperation(callback) {
DBOpenRequest.onupgradeneeded = function(event) {
let db = event.target.result;
DBOpenRequest.onupgradeneeded = function(event) {
let db = event.target.result;
- db.createObjectStore("compgames", { keyPath: "vname" });
+ let upgradeTransaction = event.target.transaction;
+ if (!db.objectStoreNames.contains("compgames"))
+ db.createObjectStore("compgames", { keyPath: "vname" });
+ else
+ upgradeTransaction.objectStore("compgames");
};
}
export const CompgameStorage = {
add: function(game) {
};
}
export const CompgameStorage = {
add: function(game) {
- dbOperation((err,db) => {
+ dbOperation((err,
db) => {
if (err) return;
let objectStore = db
.transaction("compgames", "readwrite")
if (err) return;
let objectStore = db
.transaction("compgames", "readwrite")
@@
-44,13
+49,13
@@
export const CompgameStorage = {
// obj: move and/or fen
update: function(gameId, obj) {
// 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?
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]);
const game = event.target.result;
Object.keys(obj).forEach(k => {
if (k == "move") game.moves.push(obj[k]);
@@
-65,7
+70,7
@@
export const CompgameStorage = {
// Retrieve any game from its identifier (variant name)
// NOTE: need callback because result is obtained asynchronously
get: function(gameId, callback) {
// 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");
let objectStore = db
.transaction("compgames", "readonly")
.objectStore("compgames");
@@
-77,7
+82,7
@@
export const CompgameStorage = {
// Delete a game in indexedDB
remove: function(gameId) {
// Delete a game in indexedDB
remove: function(gameId) {
- dbOperation((err,db) => {
+ dbOperation((err,
db) => {
if (!err) {
db.transaction("compgames", "readwrite")
.objectStore("compgames")
if (!err) {
db.transaction("compgames", "readwrite")
.objectStore("compgames")