lichenma / SuDuoku

0 stars 0 forks source link

Redesign state communication #5

Open lichenma opened 3 years ago

lichenma commented 3 years ago

Context

Currently, everything works by sending the state variable to the server and then once the server replies we change the state to match the state kept in the server. There problems with this due to heroku having a 2 second delay at times communicating from client to server and over to another client. We want to move to a state where we keep the client states and only perform updates when the server replies to us - figure out a logic for combining states in a way that makes sense.

lichenma commented 3 years ago
lichenma commented 3 years ago

The initial implementation will feature state being passed with the following schema:

We will be adding the parameters lastUpdated and lastUpdatedUser -> next step of the process would be to introduce methods to the frontend and backend which only accepts changes that are more recent than the current changes.

In the future for most use cases, only the puzzle object is utilized so we will aim to only pass this aspect of the state to websockets -> to be visited in a future PR

{
   board : Map {

      puzzle: List [
         List [
            Map {
              value: Integer 
              prefilled: Boolean 
              notes: Array
              -->    lastUpdated: Date
              -->    lastUpdatedUser: String
           } 
        ]
      ]

      groupSelected: Array
      choices: Map
      selected: Array
   }

   history : List 
   historyOffset: Integer 
   solution: Array[Array[9]]
}