Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
orestis opened this issue Mar 12, 2019 · 1 comment
Closed

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

orestis opened this issue Mar 12, 2019 · 1 comment
Labels
bug Something isn't working

Comments

@orestis
Copy link
Member

orestis commented Mar 12, 2019

(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
Copy link
Collaborator

👍Fixed in 3272afe

@lilactown lilactown added the bug Something isn't working label Mar 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants