TraverseEntities

View source

Defines the contract for a relationship that can expose related entities.

Implementations return child EntityHandle values from TraverseEntities#visit so relationship queries can traverse them. They also implement TraverseEntities#map to remap the packed EntityId values held by the relationship when entities are copied or restored.

This class is an interface-like base contract. Both methods throw the abstract-method error until an implementing class overrides them.

Examples

import { EntityHandle } from '@wimaengine/ecs'
import { TraverseEntities } from '@wimaengine/relationship'

class ChildLinks extends TraverseEntities {
  constructor(children) {
    super()
    this.children = children
  }

  visit() {
    return this.children
  }

  map(entityMap) {
    this.children = this.children.map((child) =>
      EntityHandle.from(entityMap.get(child.id()))
    )
  }
}

Constructor


constructor()

Methods


visit(): EntityHandle[]

View source

Returns the child entities exposed by this relationship.

Relationship queries call this method to continue traversal. The returned values are EntityHandle instances, not packed entity IDs.

Throws

Always in the base implementation until overridden.

Returns

Child entity handles.

map(_entityMap: Map<number, number>): void

View source

Remaps the entity IDs held by this relationship.

The map contains packed source-to-target EntityId values. Implementations should use it to replace each relationship target with the corresponding EntityHandle for the copied or restored entity.

Parameters

NameDescriptionDefault
_entityMap

Packed source-to-target entity IDs.

—

Throws

Always in the base implementation until overridden.