From e5e73c78f04015c99536bce368a2330f297f4afe Mon Sep 17 00:00:00 2001 From: s-ol Date: Fri, 5 Feb 2021 16:25:50 +0100 Subject: react-ify --- src/dom.js | 42 ------------------------------------------ 1 file changed, 42 deletions(-) (limited to 'src/dom.js') diff --git a/src/dom.js b/src/dom.js index dd15902..45f8a7a 100644 --- a/src/dom.js +++ b/src/dom.js @@ -11,45 +11,3 @@ export const css = ([ code] ) => { return style; }; - -const appendChild = (parent, child) => { - if (child === null || child === undefined || child === false) - return; - - if (Array.isArray(child)) { - child.forEach((nestedChild) => appendChild(parent, nestedChild)); - } else { - parent.appendChild(child.nodeType ? child : document.createTextNode(child)); - } -} - -const objectProps = { style: true, dataset: true }; - -export const createElement = (tag, props, ...children) => { - if ('function' === typeof tag) - return tag(props, children); - - const element = document.createElement(tag); - - for (const [name, value] of Object.entries(props || {})) { - if (name.startsWith('on') && name.toLowerCase() in window) { - element.addEventListener(name.toLowerCase().substr(2), value); - } else if (name === 'css') { - for (const [prop, val] of Object.entries(value)) { - element.style.setProperty(prop, val); - } - } else if (objectProps[name]) { - Object.assign(element[name], value); - } else { - element.setAttribute(name, value.toString()); - } - } - - for (const child of children) { - appendChild(element, child); - } - - return element; -} - -export const createFragment = (props, ...children) => children; -- cgit v1.2.3