nosco / hx

A simple, easy to use library for React development in ClojureScript.
MIT License
247 stars 16 forks source link

Destructuring defnc :keys [class] has weird behaviour #36

Closed orestis closed 5 years ago

orestis commented 5 years ago
(defnc MyComponent[{:keys [variant class-name class]
                       :or {variant :down class "foo" class-name "bar"}}]
  (println "class" (if class class "CLASS NOT TRUTHY"))
  (println "classname" (if class-name class-name "CLASSNAME NOT TRUTHY"))

[:div "something"])

When invoking the above code like:

[MyComponent {:variant :up}]

The following is printed:

class CLASS NOT TRUTHY
classname bar

But when invoking it with:

[MyComponent {:class "hx-rocks"}]
class hx-rocks
classname hx-rocks

It seems that :class is set unconditionally to nil in that map, so that the keys destructuring doesn't work. I made this small repro using plain ClojureScript to make sure:

(defn TEST [{:keys [a b] :or {a 1 b 2}}]
  (println "A" a "B" b))

(TEST {:a nil})

This prints: A nil B 2.

lilactown commented 5 years ago

👍Fixed in https://github.com/Lokeh/hx/commit/3272afefcec559708ac7a2569f1a4bb886be17b4