@sova The way you'd do server side rendering (IMHO) is to create a simple tree of initial data, a root react factory, and just call that and pass the result to render-to-string. No parser needed in Om or Untangled. The use of Untangled's InitialAppState technique would be quite useful for generating exactly what you want in this case.
@danielgrosse Each component to go on the screen is composed into a React vdom rendering tree. The queries are the same: each component's query composes in the immediate child queries, just like each component's render composes in the child components via render. When I say top-level properties, I'm typically referring to the properties queried at the root of the UI tree.
@tony.kay ah cool, thanks a lot for sharing your thoughts. i'm trying to see what the "tree of initial data" looks like .. is it an atom? coming from js/json i'm trying to find the clojure equivalent of json arrays...
It's just a nested data structure
{ :root 1 :child {:x 2 :subchild { ... }}}
to go with a nested UI Root renders Child which render Subchild
in that section of the devguide you can see the queries, initial app state, and rendering all composing together
https://www.youtube.com/watch?v=vzIrgR9iXOw&index=4&list=PLVi9lDx-4C_T_gsmBQ_2gztvk6h_Usw6R
The video is probably a good way to get a feel for it.
Another nice thing about Om/Untangled: There is only Clojure(script) and EDN (extensible data notation...the data language of clojure itself). No javascript. No JSON. Everything is unified.
well, and since it is react: no html (of consequence) either
Yo! Thank you so much. It's satisfying to know that I'm gradually coming to the same conclusions for design and project layout as greater minds before me have.
We've generated a lot of docs/videos. Trying to make it easy to get going 😉
Rock on. If my initial state is provided by Datomic, I can just do some server-side queries to get the initial load... is that the easiest way?
Sure. Graph queries on Datomic do return trees of data. They may not align with your UI perfectly, so you usually will have to massage them a bit
In that case you would not use InitialAppState at all...just make the tree and pass it to a render of the root
(def ui-root (om/factory Root))
(dom/render-to-string (ui-root initial-tree-of-data))
Hey all. I just finished a preliminary version of server-side rendering and pushed it to untangled-client on clojars as 0.6.2-SNAPSHOT
There is a spec (server-rendering-spec) that shows the usage
There are some gotchas: You cannot call protocols on a defui component directly in clj. So, I made a get-initial-state
function.
If you're using (ident)
or (query)
directly in your code it won't work.
this is an Om limitation, not Untangled
This is NOT on develop yet. The source is on a (published) branch on github: feature/server-side-rendering