mirror of
https://github.com/status-im/reagent.git
synced 2025-01-12 04:44:27 +00:00
Check if value is named before calling name
This commit is contained in:
parent
d592335612
commit
e1019a1c9c
@ -122,14 +122,18 @@
|
||||
;; Merge classes
|
||||
class
|
||||
(assoc :class (let [old-class (:class props)]
|
||||
(if (nil? old-class) class (str class " " (name old-class))))))))
|
||||
(if (nil? old-class) class (str class " " (if (named? old-class)
|
||||
(name old-class)
|
||||
old-class))))))))
|
||||
|
||||
(defn stringify-class [{:keys [class] :as props}]
|
||||
;; (keep name) doesn't work because class vector could contain false, which is not Named
|
||||
(if (coll? class)
|
||||
(->> class
|
||||
(filter identity)
|
||||
(map name)
|
||||
(keep (fn [c]
|
||||
(if c
|
||||
(if (named? c)
|
||||
(name c)
|
||||
c))))
|
||||
(string/join " ")
|
||||
(assoc props :class))
|
||||
props))
|
||||
|
@ -574,19 +574,24 @@
|
||||
(is (= (rstr [:p {:class #{"a" "b" "c"}}])
|
||||
(rstr [:p {:class "a b c"}]))))
|
||||
|
||||
(deftest class-named-values
|
||||
(is (= (rstr [:p {:class :a}])
|
||||
(rstr [:p {:class "a"}])))
|
||||
(is (= (rstr [:p.a {:class :b}])
|
||||
(rstr [:p {:class "a b"}])))
|
||||
(is (= (rstr [:p.a {:class 'b}])
|
||||
(rstr [:p {:class "a b"}])))
|
||||
(is (= (rstr [:p {:class [:a :b]}])
|
||||
(rstr [:p {:class "a b"}])))
|
||||
(is (= (rstr [:p {:class ['a :b]}])
|
||||
(rstr [:p {:class "a b"}])))
|
||||
(deftest class-different-types
|
||||
(testing "named values are supported"
|
||||
(is (= (rstr [:p {:class :a}])
|
||||
(rstr [:p {:class "a"}])))
|
||||
(is (= (rstr [:p.a {:class :b}])
|
||||
(rstr [:p {:class "a b"}])))
|
||||
(is (= (rstr [:p.a {:class 'b}])
|
||||
(rstr [:p {:class "a b"}])))
|
||||
(is (= (rstr [:p {:class [:a :b]}])
|
||||
(rstr [:p {:class "a b"}])))
|
||||
(is (= (rstr [:p {:class ['a :b]}])
|
||||
(rstr [:p {:class "a b"}]))))
|
||||
|
||||
(testing "class collection can contain false value"
|
||||
(testing "non-named values like numbers"
|
||||
(is (= (rstr [:p {:class [1 :b]}])
|
||||
(rstr [:p {:class "1 b"}]))))
|
||||
|
||||
(testing "falsey values are filtered from collections"
|
||||
(is (= (rstr [:p {:class [:a :b false nil]}])
|
||||
(rstr [:p {:class "a b"}])))) )
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user