choojs / nanocomponent

🚃 - create performant HTML components
https://leaflet.choo.io/
MIT License
366 stars 30 forks source link

remove placeholder concept #31

Closed juliangruber closed 7 years ago

juliangruber commented 7 years ago

https://github.com/moroshko/shallow-equal/pull/2#issuecomment-298434028 raised a concern that I didn't have an answer for, why do we even use .isSameNode() when we can just check for strict equality ===.

Nanomorph will stop looking into a node's children when a.isSameNode(b) which is true when a === b by default. So no need to even return the placeholder. As a bonus, we won't see the placeholder in the dom any more for cases where say people render and reorder lists without implementing the ID convention.

juliangruber commented 7 years ago

Maybe there is cases though that I don't yet see where this would break?

juliangruber commented 7 years ago

actually..this is slower. But I don't understand, why.

yoshuawuyts commented 7 years ago

This is what we tried initially but it's problematic because any given DOM node can only live in a single tree at any point in time. If a node, for whatever reason, is on two trees at the same time, it will unmount from one of the trees and trigger the corresponding on-load events. That's why we went through all the trouble of using proxy nodes and .isSameNode() checks to make sure the lifecycle events aren't triggered when they shouldn't.

Hope this makes sense. Thanks!

juliangruber commented 7 years ago

dang, ok yeah makes sense. thanks for clarifying!