lilactown / helix

A simple, easy to use library for React development in ClojureScript.
Eclipse Public License 2.0
624 stars 52 forks source link

Confusing syntax with `wrap` and args destructuring #110

Closed lilactown closed 1 year ago

lilactown commented 1 year ago

Ran into this in a PR last week, where someone had originally done

(defnc my-component
  [{:keys [foo bar]}]
  {:wrap (with-baz #(str foo bar))}
  ,,,)

Which syntactically looks right, but actually foo bar aren't destructured until after with-baz is called to wrap the component. The author corrected their code, but I was confused why they changed it!

Perhaps we should move the :wrap metadata above the args so that it's clearer what's in scope?

(defnc my-component
  {:wrap (with-baz #(str (:foo %) (:bar %))}
  [{:keys [foo bar]}]
  ,,,)
dvingo commented 1 year ago

👍🏾 This is also aligned with metadata forms on defn