Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Last active March 27, 2021 18:37
Show Gist options
  • Save WebReflection/61cd9581da1783f71196 to your computer and use it in GitHub Desktop.
Save WebReflection/61cd9581da1783f71196 to your computer and use it in GitHub Desktop.
Basic Proxy usage compatible with Custom Elements, using `append` DOM.next entry
// 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