// Optional callback to get error status
add: function(game, callback) {
dbOperation((err,db) => {
- if (err) {
+ if (!!err) {
callback("error");
return;
}
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);
});
},
// 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 = [];
// 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);