Yew: Implement PartialEq for VChild

Created on 12 May 2020  路  6Comments  路  Source: yewstack/yew

I'm trying to use ChildrenWithProps in a component, and to implement the Component::change method correctly for a Component with the ChildrenWithProps in it's properties, however this isn't really currently possible because to derive/implement PartialEq for the component's Props requires the VChild (in the ChildrenWithProps) implements PartialEq.

My exact use case can be seen at
https://github.com/kellpossible/coster/blob/5dd0ea17d0501368812c0b9785e54a1afd197ce2/gui/yew-state/src/provider.rs#L80 and
https://github.com/kellpossible/coster/blob/5dd0ea17d0501368812c0b9785e54a1afd197ce2/gui/yew-state/src/provider.rs#L191

feature

All 6 comments

Related, I also noticed that VNode PartialEq implementation is missing for VComp:

// Need to improve PartialEq for VComp before enabling

Which would also imply that the Children's PartialEq implementation is also broken when it contains a Component child.

Not exactly "broken", it will just always treat component nodes as not equal.

This will all be possible when we finish up https://github.com/yewstack/yew/issues/830

@jstarry thanks for the feedback! Is there anything I can do to help for that issue? I'm using these features while working on a Redux-like Provider component as an experiment for managing global state.

@kellpossible yes, I think you could but I need to do a bit of housecleaning first. I'll get back to you in a few days on this!

Hey @kellpossible, I spent some time looking into this and realized I was conflating ChildrenRenderer<VChild<CHILD>> and ChildrenRenderer<Html>. There's nothing blocking implementing PartialEq for VChild right now. I think we just need to implement it for when a component's properties implement PartialEq and comparing props should be sufficient.

Do you want to take on this task?

Here is an issue for tracking the fix for Children: https://github.com/yewstack/yew/issues/1236

@jstarry okay I'll give it a crack today!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kellytk picture kellytk  路  3Comments

thienpow picture thienpow  路  3Comments

zethra picture zethra  路  5Comments

sanpii picture sanpii  路  3Comments

ghost picture ghost  路  5Comments