-
Notifications
You must be signed in to change notification settings - Fork 83
default values for newChild and updateChild #80
Comments
I like the idea of having good defaults. In #81 we discussed another one for For In general the less config we can mandate, the more |
Yeah, it should be fine to search for a distributed template and fallback to a generic div. It would make sense to recycle by default to further optimize performance. Maybe something like this? constructor() {
super();
// ...
let childTemplate = null;
const nodePool = [];
this[_newChild] = () => {
if (!childTemplate) {
// Use distributed template or a generic div
childTemplate = this.querySelector('template') || document.createElement('div');
}
return nodePool.pop() || childTemplate.cloneNode(true);
};
this[_updateChild] = (child, item) => child.textContent = item.toString();
this[_recycleChild] = (child) => nodePool.push(child);
} |
Sorry for the late response, but yes, that seems pretty great to me! |
What about setting these default values for newChild and updateChild?
The user can still override these values to customize the scroller.
A default
newChild
helps especially those template libraries that need a container to render within, e.g. lit-html and preact. With lit-html, the user would just need to do this to update the nodes:The text was updated successfully, but these errors were encountered: