+ });
+ } else {
+ // live
+ dbOperation(db => {
+ let objectStore = db
+ .transaction("games", "readwrite")
+ .objectStore("games");
+ objectStore.get(gameId).onsuccess = function(event) {
+ const game = event.target.result;
+ Object.keys(obj).forEach(k => {
+ if (k == "move") game.moves.push(obj[k]);
+ else game[k] = obj[k];
+ });
+ objectStore.put(game); //save updated data
+ };
+ });
+ }
+ },
+
+ // Retrieve all local games (running, completed, imported...)
+ getAll: function(callback) {
+ dbOperation(db => {
+ let objectStore = db.transaction("games").objectStore("games");
+ let games = [];
+ objectStore.openCursor().onsuccess = function(event) {
+ let cursor = event.target.result;
+ // if there is still another cursor to go, keep running this code
+ if (cursor) {
+ games.push(cursor.value);
+ cursor.continue();
+ } else callback(games);
+ };