remove support for refs

not really needed, as render functions work with DOM nodes
that can be easily stored as a side-effect of the render fn
This commit is contained in:
Bruno Windels 2019-06-14 22:41:50 +02:00
parent 553bda2837
commit 773b4ed941

View file

@ -20,7 +20,6 @@ import { setAttribute, text, TAG_NAMES } from "./html.js";
export default class Template {
constructor(value, render) {
this._value = value;
this._refs = {};
this._eventListeners = [];
this._bindings = [];
this._render = render;
@ -37,10 +36,6 @@ export default class Template {
return this._root;
}
ref(name) {
return this._refs[name];
}
update(value) {
this._value = value;
for (const binding of this._bindings) {
@ -60,8 +55,6 @@ export default class Template {
}
}
_addRef(name, node) {
this._refs[name] = node;
}
_addEventListener(node, name, fn) {
@ -112,9 +105,7 @@ export default class Template {
if (attributes) {
for(let [key, value] of Object.entries(attributes)) {
const isFn = typeof value === "function";
if (key === "ref") {
this._refs[value] = node;
} else if (key.startsWith("on") && key.length > 2 && isFn) {
if (key.startsWith("on") && key.length > 2 && isFn) {
const eventName = key.substr(2, 1).toLowerCase() + key.substr(3);
const handler = value;
this._addEventListener(node, eventName, handler);