Defines an event in your component metadata that can be dispatched by
the component.
Make sure your event name starts with on and to avoid conflicts with
native HTMLElement events. The event name will be converted to kebab-case.
You can dispatch events either using HTMLElement.dispatchEvent or by
calling the event emitter function in this.events inside the render
function of a component.
@example
classAppextendsComponent("x-app",{ onSomethingHappen:event<string>(), // Event name will be `something-happen` }){ render(){ // … this.events.onSomethingHappen({ detail:"Something happened! "}); } } const app =newApp(); app.addEventListener("something-happen",(evt)=>{ // `evt` is `CustomEvent<string>` console.log(evt.detail); });
Defines an event in your component metadata that can be dispatched by the component.
Make sure your event name starts with
onand to avoid conflicts with nativeHTMLElementevents. The event name will be converted to kebab-case.You can dispatch events either using
HTMLElement.dispatchEventor by calling the event emitter function inthis.eventsinside therenderfunction of a component.You can also provide a custom event constructor: