From e78de4bab9bc93669101dc9cd1019bfb4e8dcfd5 Mon Sep 17 00:00:00 2001
From: Yannick Li <yannick.li@concordant.io>
Date: Fri, 9 Jul 2021 12:14:02 +0200
Subject: [PATCH] Group the MVMap updates

Group the MVMap updates during a reset/reconnection.
---
 collaborative/src/components/Game.tsx | 36 +++++++++++++--------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/collaborative/src/components/Game.tsx b/collaborative/src/components/Game.tsx
index ce98b75..e60544b 100644
--- a/collaborative/src/components/Game.tsx
+++ b/collaborative/src/components/Game.tsx
@@ -145,17 +145,17 @@ class Game extends React.Component<Record<string, unknown>, IGameState> {
   switchConnection(): void {
     this.setState({ isConnected: !this.state.isConnected });
     if (this.state.isConnected) {
-      for (let index = 0; index < 81; index++) {
-        if (
-          this.state.cells[index].modifiable &&
-          this.modifiedCells[index] !== null
-        ) {
-          session.transaction(client.utils.ConsistencyLevel.None, () => {
+      session.transaction(client.utils.ConsistencyLevel.None, () => {
+        for (let index = 0; index < 81; index++) {
+          if (
+            this.state.cells[index].modifiable &&
+            this.modifiedCells[index] !== null
+          ) {
             this.state.mvmap.setString(index, this.modifiedCells[index]);
-          });
+          }
         }
-      }
-      this.setGetTimeout();
+      });
+      this.pullGrid();
     } else {
       clearInterval(this.timeoutGet);
       this.modifiedCells = new Array(81).fill(null);
@@ -181,18 +181,18 @@ class Game extends React.Component<Record<string, unknown>, IGameState> {
    */
   reset(): void {
     const cells = this.state.cells;
-    for (let index = 0; index < 81; index++) {
-      if (cells[index].modifiable) {
-        cells[index].value = "";
-        if (this.state.isConnected) {
-          session.transaction(client.utils.ConsistencyLevel.None, () => {
+    session.transaction(client.utils.ConsistencyLevel.None, () => {
+      for (let index = 0; index < 81; index++) {
+        if (cells[index].modifiable) {
+          cells[index].value = "";
+          if (this.state.isConnected) {
             this.state.mvmap.setString(index, cells[index].value);
-          });
-        } else {
-          this.modifiedCells[index] = "";
+          } else {
+            this.modifiedCells[index] = "";
+          }
         }
       }
-    }
+    });
     this.setState({ cells: cells });
   }
 
-- 
GitLab