You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@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 a bool (ShouldRender), but it would be ignored when update is directly called by the parent. We ONLY want to re-render the child's state when child.update() changed its state, we don't want to return true from the parent's update() 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's deref_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 the dirty flag is true though) and then request a re-render of the component's DOM.
What do you think? :)
The text was updated successfully, but these errors were encountered:
@jstarry Yes, that would make sense. But also having something like PureComponent that does the comparison:
Consider using the built-in PureComponent instead of writing shouldComponentUpdate() by hand. PureComponent performs a shallow comparison of props and state, and reduces the chance that you’ll skip a necessary update.
@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? :)
The text was updated successfully, but these errors were encountered: