mics
mics copied to clipboard
Exceptions extending HTMLElement
I like your API a lot. This code fails though:
const SimpleGreeting = mix(HTMLElement, Base => class extends Base {});
customElements.define("simple-greeting", SimpleGreeting);
It gets the following exception in the derive() method:
Uncaught TypeError: Failed to construct 'HTMLElement': Please use the 'new' operator, this DOM object constructor cannot be called as a function.
I tried to build using mics' source, in order to debug it, i.e. doing an
import { mix } from "mics/src/index";
rather than
import { mix } from "mics";
That strangely gives me a different error:
Uncaught TypeError: Failed to execute 'define' on 'CustomElementRegistry': constructor argument is not a constructor
That's because mix() is returning (...args) => new Class(...args) rather than the class itself. (See related ticket #46.)
Luckily I can work around that by referencing SimpleGreeting.class instead of SimpleGreeting.