Fork me on GitHub
#untangled
<
2017-01-03
>
tony.kay01:01:21

@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.

tony.kay01:01:01

@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.

sova-soars-the-sora01:01:33

@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...

tony.kay01:01:05

It's just a nested data structure

tony.kay01:01:30

{ :root 1 :child {:x 2 :subchild { ... }}}

tony.kay01:01:49

to go with a nested UI Root renders Child which render Subchild

tony.kay01:01:25

in that section of the devguide you can see the queries, initial app state, and rendering all composing together

tony.kay01:01:45

The video is probably a good way to get a feel for it.

tony.kay01:01:01

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.

tony.kay01:01:43

well, and since it is react: no html (of consequence) either

sova-soars-the-sora01:01:50

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.

tony.kay01:01:41

We've generated a lot of docs/videos. Trying to make it easy to get going 😉

sova-soars-the-sora02:01:42

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?

tony.kay02:01:34

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

tony.kay02:01:05

In that case you would not use InitialAppState at all...just make the tree and pass it to a render of the root

tony.kay02:01:16

(def ui-root (om/factory Root))

tony.kay02:01:28

(dom/render-to-string (ui-root initial-tree-of-data))

tony.kay22:01:21

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

tony.kay22:01:33

There is a spec (server-rendering-spec) that shows the usage

tony.kay22:01:59

There are some gotchas: You cannot call protocols on a defui component directly in clj. So, I made a get-initial-state function.

tony.kay22:01:18

If you're using (ident) or (query) directly in your code it won't work.

tony.kay22:01:24

this is an Om limitation, not Untangled

tony.kay22:01:06

This is NOT on develop yet. The source is on a (published) branch on github: feature/server-side-rendering