Class Part<StateType>Abstract

Base class for all parts.

Type Parameters

  • StateType

Hierarchy

Properties

_attachedElement?: HTMLElement

The DOM element to which this part was last rendered.

_mountElement?: HTMLElement

The DOM element to which which this part has been explicitly mounted. (Will be undefined for all except root parts)

Accessors

  • get element(): null | HTMLElement
  • Returns

    Either this part's explicit mount element, or the element found by its id. This will return null if the part is un-attached parts, i.e.:

    • Root elements that have never been mounted
    • Child elements that have never been rendered
    • Child elements that have since been orphaned by their parents

    Returns null | HTMLElement

  • get isAttached(): boolean
  • Returns

    Whether or not the part is currently in the DOM tree with either a parent or a valid DOM element mount point.

    Returns boolean

  • get isRoot(): boolean
  • Returns

    Whether the part is a root part (doesn't have a parent, is mounted directly to a DOM element).

    Returns boolean

  • get name(): string
  • Returns

    the name of the part class.

    Returns string

  • get parentClasses(): string[]
  • Subclasses can override this to provide a list of classes to apply to the parent element.

    Returns string[]

Methods

  • Attaches event listeners to this.element (if needsEventListeners() has been called) Needs to be protected for FormPart.

    Returns void

  • Recursively crawls the children to see if any is dirty, then renders their entire branch. If they're only stale, calls the update() method.

    Parameters

    • frame: number

    Returns void

  • Requests the next animation frame to render the part.

    Returns void

  • Tells the children that they need to attach event listeners.

    Parameters

    • includeMe: boolean

      only set _needsEventListeners on this if it's true

    Returns void

  • Recursively calls update() on this part and all of its children.

    Returns void

  • Attaches an event listener for a particular type of HTML event. Only event types with Tuff listeners will have HTML listeners attached.

    Parameters

    • elem: HTMLElement
    • type: keyof HTMLElementEventMap

    Returns void

  • Mark this part as dirty, meaning it needs to be fully re-rendered.

    Returns void

  • Emits a generic message associated with the part (as opposed to a DOM event).

    Type Parameters

    • DataType

    Parameters

    • key: TypedKey<DataType>

      the message key

    • data: DataType

      data associated with the message

    • Optional options: EmitOptions

      configures how the message is emitted

    Returns void

  • Parts can override this to provide custom behavior that is run exactly once before the part is rendered for the first time.

    Returns Promise<void>

  • Listens for a generic message on the part (emitted with emitMessage()).

    Type Parameters

    • DataType

    Parameters

    • key: UntypedKey | TypedKey<DataType>

      the message key

    • handler: ((m: Message<"message", DataType>) => void)

      the message handler

        • (m: Message<"message", DataType>): void
        • Parameters

          Returns void

    • options: ListenOptions = {}

      message handling options

    Returns void

  • Parts can override this to provide custom behavior that is run after init() and whenever the page changes.

    Returns void

  • Computes a new context and loads this and all child parts. Meant to be used by Nav.

    Returns void

  • Looks up a child part by name.

    Parameters

    • name: string

      the name of the child part assigned during makePart or makeStatelessPart

    Returns undefined | StatelessPart

  • Register a wildcard listener for all global keyboard events.

    Parameters

    • listener: Listener

      the listener function

    Returns void

  • Mark this part as stale, meaning it needs to be updated but not rendered.

    Returns void

  • Gets called every time the part is rendered.

    Parameters

    • _elem: HTMLElement

      the actual DOM element containing the part

    Returns void

Generated using TypeDoc