turbodombuilder - v0.9.66
    Preparing search index...

    Function define

    • Function

      Parameters

      • className: string

        The class name, used as the registry key and to infer the tag name.

      • OptionalelementName: string

        The custom element tag name. Inferred as the kebab-case of className if omitted (e.g. "MyEl""my-el").

      • Optionaloptions: DefineOptions

        Configuration options. See DefineOptions.

      Returns any

      define

      Stage-3 class decorator factory that registers a class in the TurboDom registry and, if the class extends a DOM element, also registers it as a custom HTML element. Specifically, it:

      • Registers the class in the registry by RegistryCategory, inferring the category from the class's inheritance chain.
      • If the class extends a DOM Element:
        • Registers it with the browser's customElements registry under the provided or inferred tag name.
        • Stores the tag name on the class as a static tagName property.
        • Adds the tag name as a CSS class to all instances (enabling CSS targeting by class hierarchy).
        • Wraps the static create() method to automatically inject the tag name into creation properties.
        • Publishes a live observedAttributes getter aggregating all @observe-decorated fields across the entire class hierarchy.
        • Optionally injects an attributeChangedCallback that mirrors HTML attribute changes to their corresponding @observe-decorated fields, and vice versa.
      @define("MyEl")           // tag inferred as "my-el"
      class MyEl extends TurboElement { ... }

      @define("MyEl", "my-el") // explicit tag name
      class MyEl extends TurboElement { ... }

      @define("MyModel") // non-element: only registered in TurboDom registry
      class MyModel extends TurboModel { ... }
    • Function

      define

      Type Parameters

      • Type extends new (...args: any[]) => any

      Parameters

      • Base: Type

        The class to register.

      • OptionalelementName: string

        The custom element tag name. Inferred as the kebab-case of className if omitted.

      • OptionalclassName: string

        The class name, used as the registry key. Inferred from Base.name if omitted.

      • Optionaloptions: DefineOptions

        Configuration options. See DefineOptions.

      Returns Type

      The class, unchanged, after all setup has been applied.

      Imperative equivalent of the @define decorator. Applies identical registration and setup logic without requiring decorator syntax — useful for dynamically registering classes at runtime, or in build environments where class decorators cause unwanted output transformations.

      When the class extends a DOM Element, it:

      • Registers it with the browser's customElements registry.
      • Stores the tag name as a static tagName property.
      • Adds the tag name as a CSS class to all instances.
      • Wraps the static create() method to automatically inject the tag.
      • Publishes a live observedAttributes getter across the class hierarchy.
      • Optionally injects an attributeChangedCallback attribute bridge.

      For all classes (element or not), it registers the class in the registry by RegistryCategory.

      class MyEl extends TurboElement { ... }
      define(MyEl); // className → "MyEl", tag → "my-el"
      define(MyEl, "my-el"); // explicit tag, className inferred
      define(MyEl, "my-el", "MyEl"); // both explicit

      class MyModel extends TurboModel { ... }
      define(MyModel, undefined, "MyModel"); // non-element, registry only