htmlhammer icon indicating copy to clipboard operation
htmlhammer copied to clipboard

Check if component aleady exists when creating custom element?

Open vsmid opened this issue 3 years ago • 0 comments

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);
};

vsmid avatar Nov 22 '22 15:11 vsmid