diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2021-02-05 15:25:50 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2021-02-05 15:25:50 +0000 |
| commit | e5e73c78f04015c99536bce368a2330f297f4afe (patch) | |
| tree | 05bd064a700ebe72dc428ea57515f38105f9a05c /src/dom.js | |
| parent | lazy-load graph.json (diff) | |
| download | fedidag-e5e73c78f04015c99536bce368a2330f297f4afe.tar.gz fedidag-e5e73c78f04015c99536bce368a2330f297f4afe.zip | |
react-ify
Diffstat (limited to 'src/dom.js')
| -rw-r--r-- | src/dom.js | 42 |
1 files changed, 0 insertions, 42 deletions
@@ -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; |
