Add debug traces to understand what happens with first corr move
[vchess.git] / client / src / utils / gameStorage.js
index cc7dca5..2756496 100644 (file)
@@ -7,7 +7,6 @@
 //   cadence: string,
 //   increment: integer (seconds),
 //   type: string ("live" or "corr")
-//   imported: boolean (optional, default false)
 //   // Game (dynamic) state:
 //   fen: string,
 //   moves: array of Move objects,
@@ -63,6 +62,7 @@ export const GameStorage = {
   update: function(gameId, obj) {
     if (Number.isInteger(gameId) || !isNaN(parseInt(gameId))) {
       // corr: only move, fen and score
+console.log(obj.move);
       ajax("/games", "PUT", {
         gid: gameId,
         newObj: {
@@ -97,7 +97,8 @@ export const GameStorage = {
   },
 
   // Retrieve all local games (running, completed, imported...)
-  getAll: function(callback) {
+  // light: do not retrieve moves or clocks (TODO: this is the only usage)
+  getAll: function(light, callback) {
     dbOperation((err,db) => {
       let objectStore = db.transaction("games").objectStore("games");
       let games = [];
@@ -105,7 +106,14 @@ export const GameStorage = {
         let cursor = event.target.result;
         // if there is still another cursor to go, keep running this code
         if (cursor) {
-          games.push(cursor.value);
+          let g = cursor.value;
+          if (light) {
+            g.movesCount = g.moves.length;
+            delete g.moves;
+            delete g.clocks;
+            delete g.initime;
+          }
+          games.push(g);
           cursor.continue();
         } else callback(games);
       };