The toolkit handed to an enhancer's setup. Everything registered through on/add is torn down automatically when the instance is destroyed.

interface EnhancerContext<Options extends object> {
    add: (disposer: Disposer) => void;
    container: HTMLElement | Document;
    emit: (type: string, detail?: unknown, options?: EmitOptions) => boolean;
    on: <E extends Event = Event>(
        target: EventTarget,
        type: string,
        handler: (event: E) => void,
        options?: boolean | AddEventListenerOptions,
    ) => void;
    options: Options;
    root: HTMLElement;
    uid: (prefix?: string) => string;
}

Type Parameters

  • Options extends object

Properties

add: (disposer: Disposer) => void

Register an arbitrary disposer to run on teardown.

container: HTMLElement | Document

The container the enhancer was invoked with (often document).

emit: (type: string, detail?: unknown, options?: EmitOptions) => boolean

Dispatch a bubbling hl:* CustomEvent from the root. Returns false when a cancelable event was prevented.

on: <E extends Event = Event>(
    target: EventTarget,
    type: string,
    handler: (event: E) => void,
    options?: boolean | AddEventListenerOptions,
) => void

Attach an event listener that is auto-removed on destroy.

options: Options

Options merged with the definition's defaults.

root: HTMLElement

The matched component root.

uid: (prefix?: string) => string

Generate a unique id namespaced to this enhancer.