wc-mixin/examples/dispatch.ts
Buddy 8865b49f4e Add examples page with a context manager
DSD, open/closed template, and light-DOM components that talk through
<main-context>: children register on… callbacks and share updates as events.
Served by Vite via npm run examples; examples/ is linted, formatted and
typechecked.
2026-11-10 09:59:09 -08:00

10 lines
321 B
TypeScript

/** Dispatch a `CustomEvent` from `el`. It bubbles by default so an ancestor can catch it. */
export function dispatch<T = unknown>(
el: HTMLElement,
name: string,
detail: T,
init: Omit<CustomEventInit<T>, 'detail'> = {},
): void {
el.dispatchEvent(new CustomEvent(name, { bubbles: true, ...init, detail }));
}