I'm working on a webapp prototype for a customer.  The stack will be Clojure 
top to bottom - Datomic for the data layer, Ring/Compojure/Liberator for the 
server, and Clojurescript/Om on the client.

It would be highly desirable to dynamically initialize the (client side) 
application state when the page is initially built on the server.

Example - user has bookmarked some url like '/myapp/workorders?current'.  On 
the client side, the workorder data is stored in an atom, and the presentation 
of the data is rendered by Om components.  The naive approach would be what you 
see in all the simple Om examples - start with an empty atom and then when the 
app loads and detects the '?current' param, updates its state by issuing an XHR 
call back to the server.  Of course, this is wasteful, since presumably we had 
access to that state when the page was initially rendered, so we might as well 
try to utilize it.

One way I've seen this done before with other JS frameworks is using HTML <pre> 
tags, e.g. render the state into a <pre> tag, then suck the data in during 
initialization.  This seems kind of clunky to me.

A similar option would be to dynamically generate a <script> tag that just 
creates the JS data structures (arrays and maps/objects).  Then the app when it 
initializes could either 1) read the JS data and use it to build the app state 
or 2) just wrap the JS data in an atom and use it for the app state.  The 
second option would be easier, but you give up having immutable data structures 
underlying your app data, so option 1 seems the better way to go.   

Am I on the right track here, or are there better ways to accomplish this?

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to