Options
All
  • Public
  • Public/Protected
  • All
Menu

The BaseElement class extends the built-in HTMLElement class with a bit of convenience functionality, first and foremost in the addition of the mountedCallback and removedCallback hooks. BaseElement knows how to hook into a scene and/or a game powered by three-elements, but otherwise doesn't interact with Three.js in any way. You can use it as a base class for logic-only custom components that need access to the game's ticker or renderer.

Hierarchy

Index

Constructors

constructor

  • Returns BaseElement

Properties

Private Optional _game

_game: ThreeGame

Private Optional _scene

_scene: ThreeScene

callbacks

callbacks: TickerCallbacks = ...

TICKER CALLBACKS

isMounted

isMounted: boolean = false

Static exposedProperties

exposedProperties: string[] = ...

A list of properties that can also be set through attributes on the element's tag. Attribute names are expected to be kebab-cased versions of the original property names (eg. "renderTick" can be set through the attribute "render-tick".)

Accessors

frameTick

  • Returns undefined | string | TickerFunction

  • Parameters

    Returns void

game

  • Returns the instance of ThreeGame that this element is nested under.

    Returns ThreeGame

htmlTagName

  • get htmlTagName(): string
  • Returns this element's tag name, formatted as an actual HTML tag (eg. "").

    Returns string

lateTick

  • Returns undefined | string | TickerFunction

  • Parameters

    Returns void

renderTick

  • Returns undefined | string | TickerFunction

  • Parameters

    Returns void

scene

  • Returns the instance of ThreeScene that this element is nested under.

    Returns ThreeScene

tick

  • Returns undefined | string | TickerFunction

  • Parameters

    Returns void

Methods

applyAllAttributes

  • applyAllAttributes(): void
  • Helper method that will make sure all attributes set on the element are passed through attributeChangedCallback. We mostly need this because of how we're not using observedAttributes.

    Returns void

attributeChangedCallback

  • attributeChangedCallback(key: string, _: any, value: any): boolean
  • Parameters

    • key: string
    • _: any
    • value: any

    Returns boolean

connectedCallback

  • connectedCallback(): void
  • Returns void

Protected debug

  • debug(...output: any): void
  • Parameters

    • Rest ...output: any

    Returns void

disconnectedCallback

  • disconnectedCallback(): void
  • Returns void

Protected error

  • error(...output: any): void
  • Parameters

    • Rest ...output: any

    Returns void

find

  • find<T>(fn: (node: HTMLElement) => any): undefined | T
  • Takes a function, then walks up the node tree and returns the first node where the function returns true.

    Type parameters

    • T: HTMLElement

    Parameters

    • fn: (node: HTMLElement) => any
        • (node: HTMLElement): any
        • Parameters

          • node: HTMLElement

          Returns any

    Returns undefined | T

findElementWithInstanceOf

  • findElementWithInstanceOf<T>(constructor: IConstructor<any>): undefined | T
  • Type parameters

    • T = HTMLElement

    Parameters

    • constructor: IConstructor<any>

    Returns undefined | T

Private findGame

  • Returns ThreeGame

Private findScene

  • Returns ThreeScene

mountedCallback

  • mountedCallback(): void
  • This callback is invoked when the element is deemed properly initialized. Most importantly, this happens in a microtask that is very likely executed after all the other elements in the document have finished running their connectedCallbacks.

    Returns void

removedCallback

  • removedCallback(): void
  • While disconnectedCallback is invoked whenever the element is removed from the DOM or just moved to a new parent, removedCallback will only be invoked when the element is actually being removed from the DOM entirely.

    Returns void

requestFrame

  • requestFrame(): void
  • Returns void

setAttribute

  • setAttribute(name: string, value: string): void
  • We're overloading setAttribute so it also invokes attributeChangedCallback. We do this because we can't realistically make use of observedAttributes (since we don't know at the time element classes are defined what properties their wrapped objects are exposing.)

    Parameters

    • name: string
    • value: string

    Returns void

Generated using TypeDoc