o0101 / good.html

💎 Good.HTML. A nice framework without the bad stuff. Lots of custom elements, and nice templates. Good. HTML
https://o0101.github.io/good.html/
MIT License
21 stars 2 forks source link

Call print on descendent custom element when state object changes #9

Closed o0101 closed 3 years ago

o0101 commented 3 years ago

Ok

o0101 commented 3 years ago

I need a test case to see this is not working without that

o0101 commented 3 years ago

Actually it already does this, because setting state on parent element, means we clone the state which creates new objects, which results in any object state passed below to be automatically resaved, which triggers the element to be printed again (via dependencies that are automatically collected).

And if we instead passed state to a descendent via a string key, we would need to, again, explicitly set that string key state to change, which would trigger it. The only time it wouldn't be triggered, is if we modified the existing state object properties, without calling setState, but that would be incorrect, so we wouldn't do that, and anyway, that would not be an issue specific to descendent components within shadow DOM.

We are triggering unnecessarily every time we set parent state because that clones all objects, however, because of minimal diffing, even tho the print on the descendent is called, the DOM is not updates, because no properties have changed, so this is, effectively just a check.

And we could avoid that check at the print level, by ensuring we actually check object value equivalence, not just reference equivalence, and only call print if values are changed.