Commit 1773f192 authored by Akari Labs's avatar Akari Labs

handle array children properly

parent 36bedf08
......@@ -30,6 +30,7 @@ function dom(tag, attrs, ...children) {
break;
case 'string':
element = document.createElement(tag);
if (attrs) Object.keys(attrs).forEach(k => {
const a = attrs[k];
switch (typeof a) {
......@@ -47,12 +48,14 @@ function dom(tag, attrs, ...children) {
break;
}
});
children.forEach(child => {
if (child instanceof HTMLElement)
return element.appendChild(child);
if (typeof child === 'string')
return element.append(child);
})
function addChild(child) {
if (Array.isArray(child)) child.forEach(addChild);
else if (child instanceof HTMLElement) element.appendChild(child);
else if (typeof child === 'string') element.append(child);
}
addChild(children);
break;
}
return element;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment