This commit is contained in:
Geoff Doty 2025-03-27 12:27:49 -05:00
parent bafe02e7ed
commit 83ba66afa4
1 changed files with 8 additions and 7 deletions

View File

@ -22,7 +22,7 @@ export class Mite {
if (!this.root) throw new Error(`Element ${selector} not found`); if (!this.root) throw new Error(`Element ${selector} not found`);
this.state = {}; this.state = {};
for (let key in options.state) { for (const key in options.state) {
this.state[key] = signal(options.state[key]); this.state[key] = signal(options.state[key]);
} }
@ -32,8 +32,8 @@ export class Mite {
unmounted: options.unmounted || (() => {}) unmounted: options.unmounted || (() => {})
}; };
for (let key in this.methods) { for (const key in this.methods) {
if (typeof this.methods[key] === 'function') { if (typeof this.methods[key] === "function") {
this.methods[key] = this.methods[key].bind(this); this.methods[key] = this.methods[key].bind(this);
} }
} }
@ -55,7 +55,7 @@ export class Mite {
this.scanAndBind(this.root); this.scanAndBind(this.root);
for (let key in this.state) { for (const key in this.state) {
this.update(key); this.update(key);
} }
} }
@ -78,7 +78,7 @@ export class Mite {
}); });
} }
} else if (node.nodeType === Node.ELEMENT_NODE) { } else if (node.nodeType === Node.ELEMENT_NODE) {
for (let attr of node.attributes) { for (const attr of node.attributes) {
const matches = attr.value.match(/{(\w+)}/g); const matches = attr.value.match(/{(\w+)}/g);
if (matches) { if (matches) {
if (attr.name.startsWith('@')) { if (attr.name.startsWith('@')) {
@ -181,8 +181,8 @@ export class Mite {
binding.node.style.display = this.state[key].value ? '' : 'none'; binding.node.style.display = this.state[key].value ? '' : 'none';
break; break;
case 'each': case 'each': {
let parent = this.root.querySelector(binding.parentSelector); const parent = this.root.querySelector(binding.parentSelector);
if (!parent) { if (!parent) {
console.error(`Parent node (${binding.parentSelector}) not found for r-each="${binding.originalReach}"`); console.error(`Parent node (${binding.parentSelector}) not found for r-each="${binding.originalReach}"`);
return; return;
@ -223,6 +223,7 @@ export class Mite {
parent.appendChild(clone); parent.appendChild(clone);
}); });
break; break;
}
} }
}); });
} }