// obj: chat, move, fen, clocks, score[Msg], initime, ...
update: function(gameId, obj) {
// obj: chat, move, fen, clocks, score[Msg], initime, ...
update: function(gameId, obj) {
dbOperation((err, db) => {
let objectStore = db
.transaction("games", "readwrite")
.objectStore("games");
objectStore.get(gameId).onsuccess = function(event) {
// Ignoring error silently: shouldn't happen now. TODO?
dbOperation((err, db) => {
let objectStore = db
.transaction("games", "readwrite")
.objectStore("games");
objectStore.get(gameId).onsuccess = function(event) {
// Ignoring error silently: shouldn't happen now. TODO?
let game = event.target.result;
// Hidden tabs are delayed, to prevent multi-updates:
if (obj.moveIdx < game.moves.length) return;
Object.keys(obj).forEach(k => {
if (k == "move") game.moves.push(obj[k]);
else if (k == "chat") game.chats.push(obj[k]);
let game = event.target.result;
// Hidden tabs are delayed, to prevent multi-updates:
if (obj.moveIdx < game.moves.length) return;
Object.keys(obj).forEach(k => {
if (k == "move") game.moves.push(obj[k]);
else if (k == "chat") game.chats.push(obj[k]);