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.
10 lines
321 B
TypeScript
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 }));
|
|
}
|