diff --git a/state.js b/state.js index 228efc8..e49aa7c 100644 --- a/state.js +++ b/state.js @@ -284,8 +284,12 @@ const attributeObserver = new MutationObserver(mutations => { } }) -export const component = (generator, name) => { - name = name ?? camelToKebab(generator.name) +export const component = (name, generator, methods) => { + if (typeof name === "function") { + methods = generator + generator = name + name = camelToKebab(generator.name) + } const Element = class extends HTMLElement{ constructor() { super() @@ -298,9 +302,12 @@ export const component = (generator, name) => { } }) attributeObserver.observe(this, {attributes: true}) - this.replaceChildren(generator(this)) + this.replaceChildren(generator.call(this, this.state)) } } + if (methods) { + Object.defineProperties(Element.prototype, Object.getOwnPropertyDescriptors(methods)) + } customElements.define(name, Element) return Element; }