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

Spread props do not work in (auto-defined) factory functions #74

Closed
wcerfgba opened this issue Sep 8, 2020 · 1 comment
Closed

Spread props do not work in (auto-defined) factory functions #74

wcerfgba opened this issue Sep 8, 2020 · 1 comment

Comments

@wcerfgba
Copy link

wcerfgba commented Sep 8, 2020

Hello,

I've just noticed that if I define a component like

(helix.core/defnc Foo [{:keys [bar baz]}]
  {:helix/features {:define-factory true}}
  ($ "p" bar baz))

then I cannot pass through props like

(let [props {:baz "test"}]
  (Foo {:bar "yo" :& props}))

instead I must

(let [props {:baz "test"}]
  (Foo (merge {:bar "yo"} props)))

Is this a limitation of factory functions or just a bug? I can live without :& on factory functions if they are not possible, but maybe this should be documented at docs/creating-elements.md#factory-functions ?

Thank you! 😃

@lilactown
Copy link
Owner

This is a limitation of factory functions. Spread props only work with the $ macro, or macros which use the $ macro (e.g. the macros defined in helix.dom).

Since factory functions are, as it says on the tin, functions, they can not do anything at compile time - which is what the $ macro does, rewrite the props at compile time to be akin to (merge {:bar "yo"} props).

The spread props behavior was created to optimize calls to React's createElement function. Factory functions give up this optimization, for ease of typing 😄

Hope that makes sense. Doc improvement pull requests are most welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants