Replies: 3 comments
-
I'm open to this but I think we would still want to give developers the ability to fine-tune re-renders.. something like https://reactjs.org/docs/react-component.html#shouldcomponentupdate |
Beta Was this translation helpful? Give feedback.
-
@jstarry Yes, that would make sense. But also having something like
|
Beta Was this translation helpful? Give feedback.
-
Yeah, once we have a more sophisticated diffing algorithm we will definitely want to introduce PureComponents. |
Beta Was this translation helpful? Give feedback.
-
@deniskolodin
This issue is a suggestion for Yew's design.
If we go with the solution suggested here #350 (comment) we need a way to re-render a child's DOM when its state changed after calling
child.update(ChildMsg::SomeAction)
from the parent.Currently,
Component::update()
returns abool
(ShouldRender
), but it would be ignored whenupdate
is directly called by the parent. We ONLY want to re-render the child's state whenchild.update()
changed its state, we don't want to returntrue
from the parent'supdate()
call, because the rest of the parent's DOM should NOT be re-rendered.If each component could auto-detect when its state has changed from before and after its
update()
call, it could automatically schedule its own re-rendering.In Halogen this is done by using a State monad that "manages" each component's state. This allows detecting when the component's state has been modified.
We don't have to introduce monads to get the same result, just some wrapper struct that derefs to its contents, and sets a
dirty
flag to true when it'sderef_mut()
is called (which does not mean that the state has necessarily changed (it might just be that it was mutably borrowed but not modified) but it's a good indicator that a DOM re-render might be necessary, i.e. a necessary but not sufficient condition).If we mandate that the component's real state type has to be
PartialEq
, the Yew runtime can automatically compare the "before" and "after" states (only necessary if thedirty
flag is true though) and then request a re-render of the component's DOM.What do you think? :)
Beta Was this translation helpful? Give feedback.
All reactions