Replies: 1 comment 3 replies
-
I would be up for options 2 and 3! |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've been working on porting Yewprint to Yew 0.20 lately and I noticed something: maybe the type
Html
should be cheap to clone.API perspective
When making components you need to pass props that are cheap to clone (ideally). This is part of the reason why I introduced implicit-clone to Yew. But some things in Yew are still not cheap to clone and maybe they should:
Classes
I already made a PR and this is a digression of the subject. See Make Classes cheap to clone #3021 for details.
Html
In component based frameworks you sometimes pass html nodes to your component. This is usually done through "children" like this:
But frameworks do sometimes need to differentiate components that are passed as argument. See here an example of documentation from Blueprint where we differentiate "left element" and "right element":
The equivalent in Yew would be to use the type
Html
in a property. This is what we have done in Yewprint:(
Html
is currently a type alias forVNode
)Yew perspective
Unfortunately I'm not very knowledgeable about the type
VNode
(Html
is a type alias forVNode
) but I assume the type was not made cheap to clone (put into a Rc) because there was no need internally for this.If we want to make
Html
cheap to clone, we need to figure out where to put the Rcs. I see multiple options here:Inside every variant of
VNode
:(This is just a stub code to illustrate)
Transform type alias
Html
into an struct and make it cheap to clone:The idea here is that we put the Rc on top most type. It will be cheap to clone for the users of Yew. But internally it won't impact positively Yew.
Use Rc at the lowest level:
VText
is already cheap to clone. I did not modify this code. Lets look at another:At some other level?
I personally think option 1 is bad while option 3 is probably the best. Option 2 can be an easier viable option.
Conclusion
It does seem to make sense from an API perspective. But internally, VNode is probably one of the complicated type of Yew. This means that any change in it could have big impact on: binary size and performance under some conditions. On top of that, because
VNode
is at the cross of all roads in Yew's framework, it will require the expertise of a lot of different people and a thorough review.Since I have interest in this feature I'm totally okay doing a PR at some point for this. Though I don't think I'm the best suited person as I haven't work much on VNode itself nor lifecycle nor other things that are being touched here. What bothers me the most is that it will be a big impactful PR that will require a lot of effort to review and evaluate the risks. If some of the maintainers can tell me now if they are okay with reviewing this or not it would give me confidence that this will not turn into a rotting PR in the back of the queue. Of course if I'm the only one with an interest in this it might be useless.
It's also worth noting that even though I explained why it makes sense, it is possible there are counter arguments here that proves this change is unwanted.
Beta Was this translation helpful? Give feedback.
All reactions