Class Switch<T>

Abstract base class / IComponent implementation. Provides additional convenience methods for DOM element creation & manipulation.

Type Parameters

  • T

Hierarchy (view full)

Implements

Constructors

  • Type Parameters

    • T

    Parameters

    • keyFn: Fn<T, NumOrString>
    • ctors: Record<NumOrString, Fn<T, Promise<any>>>
    • error: Fn<Error, Promise<any>> = ...
    • loader: Fn<T, Promise<any>> = ...

    Returns Switch<T>

Properties

ctors: Record<NumOrString, Fn<T, Promise<any>>>
el?: Element

This component's main DOM element, i.e. usually the element created when the component is IComponent.mounted. This element will be used as default by various helper methods in the Component class.

error: Fn<Error, Promise<any>> = ...
index?: NumOrElement
inner?: IComponent<T>
keyFn: Fn<T, NumOrString>
loader: Fn<T, Promise<any>> = ...
parent?: ParentNode
val?: T

Methods

  • Syntax sugar for $el, using this component's IComponent.el as default parent.

    Parameters

    • tag: string
    • Optional attribs: any
    • Optional body: any
    • parent: undefined | ParentNode = ...
    • Optional idx: NumOrElement

    Returns Element

  • Syntax sugar for $html, using this component's IComponent.el as default element to edit.

    Parameters

    • body: MaybeDeref<string>
    • el: HTMLElement | SVGElement = ...

    Returns void

    Remarks

    If using the default element, assumes this.el is an existing HTMLElement or SVGElement.

  • Syntax sugar for $text, using this component's IComponent.el as default element to edit.

    Parameters

    • body: any
    • el: HTMLElement | SVGElement = ...

    Returns void

    Remarks

    If using the default element, assumes this.el is an existing HTMLElement.

  • Async component lifecycle method to initialize & attach the component in the target DOM.

    The index arg is used to define the child index of where to mount the component in the parent element and SHOULD default to -1, causing the component to be appended to (rather than inserted into) the list of children. The index arg MUST be passed to any DOM creation functions used within mount() (e.g. $el, $tree). Likewise, for control-flow or wrapper components, the index arg MUST be used when mounting child components in-place of the wrapper component itself (e.g. see $list, $klist, $sub etc.).

    The optional additional varargs are only used by some component wrappers and are context specific to each.

    Parameters

    Returns Promise<Element>

  • Async component lifecycle method to remove the component from the target DOM and release any other internal resources (e.g. subscriptions).

    Returns Promise<void>

  • Component update lifecycle method. Not always used, but if it is then intended to perform internal updates to reflect incoming state arg in the DOM and/or child components.

    Parameters

    • val: T

    Returns Promise<void>

Generated using TypeDoc