diff --git a/src/template/example.html b/src/template/example.html
index d97082d..e4fb98c 100644
--- a/src/template/example.html
+++ b/src/template/example.html
@@ -5,7 +5,7 @@
-
Easy template
+
Easy template
Here's some text $textinterp interpolation, and some dynamic "$dynamicInterp".
$textinterp
@@ -13,7 +13,7 @@
@@ -29,9 +29,7 @@
-
+
diff --git a/src/template/template-e6d.js b/src/template/template-e6d.js
index 50764d2..96919cb 100644
--- a/src/template/template-e6d.js
+++ b/src/template/template-e6d.js
@@ -51,9 +51,12 @@ class TemplateE6d extends HTMLTemplateElement {
const bindAttr = [];
const bindEvent = [];
let bindContent = false;
+ let ref = null;
if (node.getAttributeNames) {
for (const attr of node.getAttributeNames()) {
- if (attr.indexOf(`data-e6d-event-`) >= 0) {
+ if (attr === `data-e6d-ref`) {
+ ref = node.getAttribute(attr);
+ } else if (attr.indexOf(`data-e6d-event-`) >= 0) {
const matches = [];
node.getAttribute(attr).matchAll(eventRegex).forEach(f => matches.push(f));
if (matches.length === 1 && matches[0].length === 3) {
@@ -89,10 +92,11 @@ class TemplateE6d extends HTMLTemplateElement {
}
}
- if (bindAttr.length !== 0 || bindEvent.length !== 0 || bindContent) {
+ if (bindAttr.length !== 0 || bindEvent.length !== 0 || bindContent || ref !== null) {
// Add a leaf!
allRoutes.push({
route: trail,
+ ref,
bind: {
attr: bindAttr,
event: bindEvent,
@@ -121,13 +125,10 @@ class TemplateE6d extends HTMLTemplateElement {
connectedCallback() {
}
- bind(obj) {
+ bind(obj = {}) {
this.preprocess();
const templated = document.importNode(this.content, true);
- if (!obj) {
- return templated;
- }
const resolve = (root, route) => {
let ptr = root;
@@ -162,8 +163,14 @@ class TemplateE6d extends HTMLTemplateElement {
return result;
};
+ const references = {};
for (const route of this.bindRoute) {
const injectTarget = resolve(templated, route.route);
+ if (route.ref) {
+ references[route.ref] = injectTarget;
+ injectTarget.removeAttribute(`data-e6d-ref`);
+ }
+
for (const attr of route.bind.attr) {
const attrValue = templateString(attr.template, obj);
if (attr.func) {
@@ -187,8 +194,8 @@ class TemplateE6d extends HTMLTemplateElement {
injectTarget.data = dataValue;
}
}
-
- return templated;
+
+ return [templated, references,];
}
}