Last active
March 27, 2021 18:37
-
-
Save WebReflection/61cd9581da1783f71196 to your computer and use it in GitHub Desktop.
Basic Proxy usage compatible with Custom Elements, using `append` DOM.next entry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://jsbin.com/tebevak/edit?js,output | |
// .append via https://github.com/WebReflection/dom4/#dom4 | |
const dom = new Proxy({}, { | |
get(target, property) { | |
return function (attrs = {}, ...children) { | |
const el = document.createElement( | |
property.replace(/[a-z][A-Z]/g, '$1-$2')); | |
for (let prop of Object.keys(attrs)) | |
el.setAttribute(prop, attrs[prop]); | |
el.append(...children); | |
return el; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment