-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Allow any type to be used as Children (take 2) #3289
Conversation
Visit the preview URL for this PR (updated for commit b00667d): https://yew-rs--pr3289-any-children-wrt96p3l.web.app (expires Sat, 17 Jun 2023 13:05:16 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
Size Comparison
|
Benchmark - SSRYew Master
Pull Request
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking the time to implement it!
{header} | ||
{for header} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't VNode
be also fine for this? {vnode}
should work fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
One question though: I don't see any error messages in tests that say "ToHtml is not implemented". Is that supposed to be like that because of From conversions? Or are failing tests missing, in which case we should add them?
I would think this as expected. |
Description
Partially supersedes #3042.
(There are some additional optimisation in the original PR, so I want to preserve the PR draft instead of closing it)
This pull request makes the following changes:
Allowing any type to be passed as
children
as long asIntoPropValue<T>
for children with typeT
.E.g.: One can now use render props as children:
Added a
ToHtml
trait. Previouslystd::fmt::Display
was the blanket implementation when a variable is referenced like{item}
, this only allows{item}
to be converted toVText
.Renderable
allows a variable to be converted to aVNode
, which gives user greater control.Users can now choose between Children, ChildrenWithProps(
ChildrenRenderer<VChild<T>>
)and
Html
for html-like Children. AsHtml
s created byhtml!
is Rc'd, it is faster to useHtml
when you don't need specific features fromChildren
andChildrenWithProps
.When a component has only 1 child, it does not pass through an iterator and
Vec
.VTag
now holdsVNode
as its children type. This optimises for single child VTag by avoiding an allocation of single child VList.This new implementation not only allows more types to be used as
children
, but also reduces code size and is faster.Checklist