...
 
Commits (2)
......@@ -13,13 +13,14 @@
*/
function reduceChild(child) {
if (Array.isArray(child)) return child.map(reduceChild);
return [child];
}
module.exports = function getDom(window) {
return function dom(tag, attrs, ...children) {
function reduceChild(child) {
if (Array.isArray(child)) return child.map(reduceChild);
return [child];
}
if (children.length === 1 && Array.isArray(children[0])) children = children[0];
if (children.length !== 0)
children = children.map(reduceChild)
......@@ -53,7 +54,7 @@ module.exports = function getDom(window) {
function addChild(child) {
if (Array.isArray(child)) child.forEach(addChild);
else if (child instanceof window.HTMLElement) element.appendChild(child);
else if (typeof child === 'string') element.append(child);
else element.append(child.toString());
}
addChild(children);
......