Skip to content

Commit

Permalink
make class-names recursive
Browse files Browse the repository at this point in the history
  • Loading branch information
roman01la committed Jul 14, 2022
1 parent bbc45f7 commit ebc1787
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion core/src/uix/compiler/attributes.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@
(reduce-kv kv-conv-shallow #js {} x)
x))

(declare class-names)

(defn class-names-coll [classes]
(let [^js/Array classes (reduce (fn [^js/Array a c]
(when ^boolean c
(->> (if (keyword? c) (-name ^not-native c) c)
(->> (if (keyword? c) (-name ^not-native c) (class-names c))
(.push a)))
a)
#js []
Expand Down
10 changes: 9 additions & 1 deletion core/test/uix/aot_test.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns uix.aot-test
(:require [clojure.test :refer [deftest is testing]]
[uix.compiler.aot :as aot]))
[uix.compiler.aot :as aot]
[uix.compiler.attributes :as attrs]))

(defmulti x identity)

Expand All @@ -18,3 +19,10 @@
(testing "should not throw when there's no Hiccup children"
(is (aot/validate-children #js [1 2 3]))
(is (aot/validate-children #js [1 [2 3] [4 [5 6]]]))))

(deftest test-interpret-attrs
(let [[props] (attrs/interpret-attrs {:class ["x" ["y" "z" ["p"]]]} #js [] false)]
(is (= "x y z p" (.-className props))))
(let [[props] (attrs/interpret-attrs {:class ["x" ["y" "z" ["p"]]]} #js [nil "id" "c l ass"] false)]
(is (= "c l ass x y z p" (.-className props)))
(is (= "id" (.-id props)))))

0 comments on commit ebc1787

Please sign in to comment.