@haiix/tcomponent
    Preparing search index...

    Class TComponent<T, IDMap>

    A practical base component class that automatically parses its template, builds its DOM, binds events, and resolves sub-components.

    Type Parameters

    • T extends Element = Element

      The type of the root DOM Element.

    • IDMap = DefaultIDMap

      Defines the exact shape of the idMap.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    context: BuildContext

    The context object for the build process.

    element: T

    The root DOM Element of the component.

    The parent component instance, if any.

    namespaceURI?: string

    The namespace URI of this component's root element.

    parseOptions?: ParseOptions

    The options passed when parsing the template.

    template: string = '<div></div>'

    The HTML string template for the component.

    uses: Record<string, typeof AbstractComponent> = {}

    A dictionary of custom components to be used within the template.

    Methods

    • Destroys the component. Automatically removes the element from the DOM and cleans up all associated event listeners.

      Returns void

    • Retrieves an internal element or sub-component by its original template ID. Leverages the IDMap generic for strict type inference.

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • id: K

        The original ID defined in the static template.

      Returns IDMap[K]

      The element, strongly typed based on the IDMap.

    • Retrieves an internal element or sub-component by its original template ID, and asserts its type at runtime.

      Type Parameters

      Parameters

      • id: K

        The original ID defined in the static template.

      • ExpectedType: ConstructorOf<E>

        The expected class (e.g., HTMLInputElement, ChildComponent).

      Returns E

      The element, strongly typed to the ExpectedType.

    • Handles errors by delegating them to the parent component, or throws if there is no parent.

      Parameters

      • error: unknown

        The error to be handled.

      Returns void

    • Retrieves the component instance associated with the given DOM element. Only returns the instance if it matches the calling class type.

      Type Parameters

      Parameters

      • this: ConstructorOf<C>
      • element: Element | null | undefined

        The root DOM element of the component.

      Returns C | undefined

      The component instance, or undefined if not found or type mismatch.

    • Retrieves the class-specific parsed templates and their dependent components (uses). If they have not been parsed yet, parses them and caches the results.

      Returns ParsedComponent

      The parsed templates and their dependencies.