From 1098ba628507750bf8362ec0658c6a95ef636380 Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Mon, 20 Oct 2025 14:38:55 +0300 Subject: Update README --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 6376fa1..003cd07 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ The function you provide to `traverse` dictates the outcome for each node: * To **update a node**, return the modified node. * To **keep a node unchanged**, return the original node. * To **remove a node**, return `nil`. +* To **replace a node with many nodes on the same level**, return a [fragment node](#fragment-nodes), which will be replaced by its children during HTML transformation. ----- @@ -120,6 +121,23 @@ For a more idiomatic and concise way to build node structures, use the `$` helpe All nodes (except text nodes) can be nested. Children are passed as the second argument (if no attributes) or the third argument (if attributes are present). +#### Fragment nodes + +You can also use fragment nodes, which are nodes with a name of `:<>` and whose children replace themselves, for example: + +```clojure +(ns my.app + (:require [dompa.nodes :refer [$ ->html]])) + +(->html [($ :button + ($ :<> + ($ "hello ") + ($ "world")))]) +;;=>
hello world
+``` + +Note that the replacement happens only in the `->html` function during the transformation process, so if you use a fragment node in your node tree and wonder why it hasn't been replaced by its children, it's because of that. + ----- ### ⚡️ Compile-Time HTML with `defhtml` -- cgit v1.2.3