nosco / hx

A simple, easy to use library for React development in ClojureScript.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Destructuring defnc :keys [class] has weird behaviour

orestis opened this issue · comments

(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.

👍Fixed in 3272afe