Options
All
  • Public
  • Public/Protected
  • All
Menu

The Entity representation, which can carry mulitple components and appear in Querys.

Hierarchy

  • Entity

Index

Properties

id: number

ID unique to this entity.

Constructors

Methods

  • Adds a component to the entity using value as the initial value.

    Type Parameters

    • T

    Parameters

    • declaration: ComponentDeclaration<T>

      The component to add.

    • value: T

      Initial value of the added component.

    Returns void

  • Checks whether a given component exists on the entity.

    Parameters

    Returns boolean

    true if the component exists, false otherwise.

  • Returns the mutable value of a given component.

    remarks

    The component is considered mutated after this, regardless of whether its value actually changed. Entity.getMutable should only be used if you're actually planning to change the value.

    Type Parameters

    • T

    Parameters

    Returns T

    The mutable value.

  • getAll(): Readonly<Record<symbol, unknown>>
  • Returns a readonly map of all component values present on the entity.

    remarks

    Note, that the values are indexed by the internal symbol representation of the component and not their declaration.

    Returns Readonly<Record<symbol, unknown>>

    A readonly map of all component values.

  • Registers a given callback to be run upon mutation to given component.

    remarks

    "Mutation" in this case means, that the value of a component changed. Addition and removal of a component is not considered a mutation.

    remarks

    Note, that since mutations are flagged while reading the observed value, the callback is likely going to run before the actual change takes place. This can be worked around by running any code accessing the updated value inside a microtask:

    example
    entity.addMutationObserver( myComponent, () => {
    // delay reading to ensure all changes have taken place
    queueMicrotask( () => {
    console.log( entity.get( myComponent ) );
    } );
    } );

    Parameters

    • declaration: ComponentDeclaration<object>

      The component to observe.

    • callback: ((entity: Entity) => void)

      The callback to run on mutation.

    Returns (() => void)

    A removal callback, that, if run, removes the mutation observer.

      • (): void
      • Registers a given callback to be run upon mutation to given component.

        remarks

        "Mutation" in this case means, that the value of a component changed. Addition and removal of a component is not considered a mutation.

        remarks

        Note, that since mutations are flagged while reading the observed value, the callback is likely going to run before the actual change takes place. This can be worked around by running any code accessing the updated value inside a microtask:

        example
        entity.addMutationObserver( myComponent, () => {
        // delay reading to ensure all changes have taken place
        queueMicrotask( () => {
        console.log( entity.get( myComponent ) );
        } );
        } );

        Returns void

        A removal callback, that, if run, removes the mutation observer.

  • isDestroyed(): boolean
  • destroy(): void

Generated using TypeDoc