From 3e4d870d6b287905c786174565a93fbd79bbb87c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asko=20N=C3=B5mm?= Date: Sat, 10 Jan 2026 14:44:59 +0200 Subject: [PATCH] Add empty-seq? function and update nodes-from-opt to handle empty sequences (#13) --- src/dompa/nodes.cljc | 8 ++++++++ test/dompa/nodes_test.cljc | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/dompa/nodes.cljc b/src/dompa/nodes.cljc index d2f8e4b..eef65d3 100644 --- a/src/dompa/nodes.cljc +++ b/src/dompa/nodes.cljc @@ -142,11 +142,19 @@ (and (sequential? coll) (> (count coll) 1))) +(defn- empty-seq? + [coll] + (and (sequential? coll) + (empty? coll))) + (defn- nodes-from-opt [opt] (cond (map? opt) opt + (empty-seq? opt) + nil + (list-of-many? opt) {:node/name :<> :node/children opt} diff --git a/test/dompa/nodes_test.cljc b/test/dompa/nodes_test.cljc index 53e502a..b1c7b0f 100644 --- a/test/dompa/nodes_test.cljc +++ b/test/dompa/nodes_test.cljc @@ -31,6 +31,20 @@ (is (= "" (list-items ["one" "two" "three"])))) +(defhtml empty-list-items [items] + ($ :ul + (map (fn [item] + ($ :li item)) + items))) + +(deftest empty-list-items-test + (testing "map over empty vector should not produce LazySeq string" + (is (= "" + (empty-list-items [])))) + (testing "map over non-empty vector should work" + (is (= "" + (empty-list-items ["one" "two"]))))) + (deftest $-test (testing "a simple node" (is (= {:node/name :div