Closed wodeni closed 5 years ago
Looks great so far, thanks for writing this up!
I think we should work out and agree on the type of State
in the frontend soon, because that influences the whole design.
For the other computations: I'd say the logic about UI actions should go in the frontend so it can update as fast as possible without making a roundtrip to the server (dragUpdate and dragShape). The other functions that involve changing the translation would likely be better as functions in the backend API (so, updateShapes
and resample
).
One question: Will multiple clients ever need to interact and share state?
Let me know when/how you want to move this forward. If you are heading out on May 7 then we should schedule a meeting before then.
Will multiple clients ever need to interact and share state?
If they do, I don't think it should happen at the Penrose "layer" of the stack. I.e. if you're referring to realtime collaboration, we should handle that behavior at the same higher-level layer that'll handle the meta-activities like collaborative editors, storing serialized states for sharing, etc. I'm eyeing playing with an Elixir/Phoenix stack (or a hacky Firebase one to start) early on this summer for that layer of the platform.
Now that State
is serializable. @maxkrieger and I will start rearchitecting the system. The first task we agreed on is to write a RESTful version of react-renderer
with (1) the WS connection, (2) compressed JSON packets of State
, and (3) the following API calls to the backend:
compileTrio
:: String -- ^ a Substance program
-> String -- ^ a Style program
-> String -- ^ an Element program
-> Either State CompilerError -- ^ an initial state generated by the backend (errors will be included in the state somehow)
step
:: State -- ^ the initial state
-> Int -- ^ the number of steps n for the optimizer to take
-> State -- ^ the resulting state after the optimizer takes n steps
stepUntilConvergence
:: State -- ^ the initial state
-> Either State OptimizerError -- ^ the converged state or optimizer errors
Overview
For each client, the backend server is single-threaded and acts as a state machine. However, we would like to make concurrent requests on both the language and graphics sides (e.g. optimizing a diagram while editing Substance program). Therefore, we propose to rewrite the backend server to be stateless and move the server logic for a single client to the frontend. Instead of keeping all states of the client in the backend, each client will store its state in the frontend and make various requests to the backend server with its state as the payload. The frontend is responsible to handle packets in a way akin to the existing state machine:
Potential benefits of this approach include:
autostep
, and handling the canvas sizeIn this document, we will:
State
overallObjFn
will be stored and composedState
rewriteHaskell backend API
We specify the backend API by going through all functions used by the existing server module and any other ad hoc computation involved:
Optimizer
step :: State -> State
: take a step in the optimizerParsers
parseDsll :: String -> String -> IO VarEnv
: takes in optionally a file name and a program string and returns an Element context (TODO: rename function toparseElement
.parseStyle :: String -> String -> VarEnv -> IO StyProg
: similarly parses a Style program with the Element context as input.parseSubstance :: String -> String -> VarEnv -> IO SubOut
: parses a Substance program in a similar way; returnsSubOut
, which isSubProg (VarEnv, SubEnv) LabelMap
.SubOut
somehow. We might not want to deal with rerouting this call through the frontend all the time. Also, there can be higher-level functions composed of these parser functions to make the process easier.compileStyle :: StyProg -> SubOut -> IO State
: takes in the Style AST, substance output and produces an initialState
.Other computation
updateShapes
: need to change the new shapes to polymorphic and update the translation and statedragUpdate
: updates existing state given drag updatedragShape
: logic used to handle drag updates depending on the type of shaperesample
: not fully encapsulated logic of resamping the state and re-evaluating the translationFrontend state machine spec
TODO: discuss with @maxkrieger
Changes needed to the existing system
TODO: discuss with @hypotext and @maxkrieger
step
. One concrete thing to check is the cost of this.VarEnv
andState
.