htmlhammer
htmlhammer copied to clipboard
Check if component aleady exists when creating custom element?
I am not sure if this is something we should be doing at all. It is ok to report duplicate element. It would also be nice to be able to write something like this without throwing error:
export default ({ }, moduleInfo) =>
customElement('dokit-provisioning', {
connectedCallback() {
this.append(div('Welcome to the Dokit Provisioning'));
}
});
Dummy solution
e.g.
export const customElement = (name, provider, type) => {
if (!customElements.get(name)) {
const CustomElement = build(provider, type);
let options = type ? { extends: type().localName } : {};
customElements.define(name, CustomElement, options);
}
return define(name);
};