- const game = event.target.result;
- if (!!obj.move)
- {
- game.moves.push(obj.move);
- game.fen = obj.fen;
- game.clocks[obj.colorIdx] += obj.addTime;
- game.initime[obj.nextIdx] = Date.now();
+ // Ignoring error silently: shouldn't happen now. TODO?
+ if (event.target.result) {
+ 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 game[k] = obj[k];
+ });
+ objectStore.put(game); //save updated data