Class Entity

An entity.

Entities are containers for collections of Components. All data in Leaf is stored in components that have been attached to Entitys.

For example, assuming you have defined a Name component as demonstrated in the defComponent example, you could add it to a new entity like so:

const ent = new Entity();

const name = ent.getOrInit(Name)
name.set("first", "John")
name.set("last", "Smith")

Constructors

Properties

Accessors

Methods

Constructors

  • Create a new Entity.

    By default the entity will have a new random ID and be initialize with no components.

    Parameters

    • Optionalid: EntityId | `leaf:${string}`

      Specifying the ID will create an entity with a specific ID instead of a random ID. The document will sill be empty, by default, so if you are loading a specific entity you may need to load the entity with a StorageManager, for instance.

    Returns Entity

Properties

The unique EntityId for this entity.

Accessors

  • get doc(): EntityDoc

    Get the internal LoroDoc.

    This can be used to do anything that Loro allows, such as exporting snapshots, doing time travel, etc.

    Note: The Entity's components are stored in this doc. If you modify the components directly through the LoroDoc you may confuse the normal entity API when it tries to read or write components.

    In the Loro doc the Entity stores one special container using the value in entityComponentsKey as it's ID. It is important that no component use this key as it's ID.

    This container will be a map that contains an entry for each component ID on the entity. The value will always be true. For every key in that map, the component is considered to be on the entity.

    Every other root container in the Loro document will be a component, and it's ID will be the component ID.

    Returns EntityDoc

Methods

  • Parameters

    • Optionaloptions: { message?: string; origin?: string; timestamp?: number }

    Returns void