Not sure what you mean. An attribute is allowed to hold any arbitrary EDN as data. So, it is perfectly legal to just put your hiccup-like thing in state, and query for it as a single attribute. Does that help, or doyou mean something else?
(defsc MyDynamicThing [this {:thing/keys [hiccup]}]
{:query [:thing/id :thing/hiccup]
:ident :thing/id
:initial-state {:thing/id 1 :thing/hiccup [:div "Hello"]}}
(sablono.core/html hiccup))
If you're instead trying to build an HTML-like model where each DOM component node is represented as a Fulcro component, then that is a bit more involved. You could generate something like this:
(declare ui-html-node)
(defmulti render-node :node/type)
(defmethod render-node :div [node]
(dom/div
(mapv ui-html-node (:node/children node))))
(defsc HTMLNode [this props]
{:query (fn [] [:node/id :node/type :node/text {:node/children ...}])
:ident :node/id}
(render-node props))
(def ui-html-node (comp/factory HTMLNode {:keyfn :node/id}))
or something like that...basically the multi-method does the detail rendering for each node, but using the (single recursive) HTMLNode during recursion.I don't recommend this latter method, actually. I worked on a project that used that approach, and it became quite complex tracing down the data model, reloading the mess, etc. The RAD approach for dynamism is much more amenable I think. You can generate such components on-the-fly and then only customize the data model definition, instead of then entire UI.
ah sorry I wrote that sloppily--I meant the latter, where I make some TreeNode
that will recursively call itself for the hiccup-y structure, pretty much what you have there, the only issue being that the nodes don't have :node/id
after they've been freshly loaded from the server, and there's no easy way to construct one from just the data in the nodes
I guess my question is, if I used an approach like the one you outline, where the right place would be to assign a random ID (like a UUID) to every node. Perhaps a pre-merge
function in HTMLNode that assigns a :node/id
if it's not present
good to know RAD handles this more gracefully though--more reason for me to sit down and learn it