Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EntityIdentifier<ValueT, ContextT>

Mixin, for the identifier that represent an entity as a whole. Requires the Identifier (or its subclass) as a base class. See more about mixins: Mixin

Type parameters

Hierarchy

Implements

  • PartOfEntityIdentifier

Index

Properties

YieldT

The type of the effects that can be "yielded" from the calculation function

context

context: this["CalcContextT"] = undefined

The scope (this value) for the calculation function.

entity

entity: EntityMeta = undefined

EntityMeta instance of the entity this identifier represents

lazy

lazy: boolean = false

Whether this identifier is lazy (true) or strict (false).

Lazy identifiers are calculated on-demand (when read from graph or used by another identifiers).

Strict identifiers will be calculated on read or during the commit call.

level

level: Levels

Level of the identifier. This attribute is supposed to be defined on the prototype level only.

name

name: any = undefined

The name of the identifiers. Not an id, does not imply uniqueness.

self

self: Entity = undefined

Reference to the Entity this identifier represents

sync

sync: boolean

Whether this identifier is sync (true) or generator-based (false). Default value is true. This attribute is supposed to be defined on the prototype level only.

Methods

calculation

  • calculation(this: this["CalcContextT"], Y: CalculationContext<this["YieldT"]>): Contexts<ValueT, this["YieldT"]>[ContextT]
  • The calculation function of the identifier. Its returning value has a generic type, that is converted to a specific type, based on the generic attribute ContextT.

    This function will receive a single argument - current calculation context (effects handler).

    When using generators, there's no need to use this handler - one can "yield" the value directly, using the yield construct.

    Compare:

    class Author extends Entity.mix(Base) {
        @field()
        firstName       : string
        @field()
        lastName        : string
        @field()
        fullName        : string
    
        @calculate('fullName')
        * calculateFullName () : ChronoIterator<string> {
            return (yield this.$.firstName) + ' ' + (yield this.$.lastName)
        }
    
        @calculate('fullName')
        calculateFullName (Y) : string {
            return Y(this.$.firstName) + ' ' + Y(this.$.lastName)
        }
    }

    Parameters

    Returns Contexts<ValueT, this["YieldT"]>[ContextT]

enterGraph

  • Template method, which is called, when this identifier "enters" the graph.

    Parameters

    Returns void

equality

  • equality(v1: ValueT, v2: ValueT): boolean
  • The equality check of the identifier. By default is performed with ===.

    Parameters

    • v1: ValueT

      First value

    • v2: ValueT

      Second value

    Returns boolean

initialize

  • initialize<T>(props?: Partial<T>): void
  • This method applies its 1st argument (if any) to the current instance using Object.assign().

    Supposed to be overridden in the subclasses to customize the instance creation process.

    Type parameters

    Parameters

    • Optional props: Partial<T>

    Returns void

leaveGraph

  • Template method, which is called, when this identifier "leaves" the graph.

    Parameters

    Returns void

readFromGraph

  • Read the value of this identifier, in the context of graph, synchronously

    Parameters

    Returns ValueT

readFromGraphAsync

  • readFromGraphAsync(graph: ChronoGraph): Promise<ValueT>
  • Read the value of this identifier, in the context of graph, asynchronously

    Parameters

    Returns Promise<ValueT>

writeToGraph

  • writeToGraph(graph: ChronoGraph, proposedValue: ValueT, ...args: this["ArgsT"]): void
  • Write a value to this identifier, in the context of graph.

    Parameters

    • graph: ChronoGraph
    • proposedValue: ValueT
    • Rest ...args: this["ArgsT"]

    Returns void

Static new

  • new<T>(this: T, props?: Partial<InstanceType<T>>): InstanceType<T>
  • This is a type-safe static constructor method, accepting a single argument, with the object, corresponding to the class properties. It will generate a compilation error, if unknown property is provided.

    For example:

    class MyClass extends Base {
        prop     : string
    }
    
    const instance : MyClass = MyClass.new({ prop : 'prop', wrong : 11 })

    will produce:

    TS2345: Argument of type '{ prop: string; wrong: number; }' is not assignable to parameter of type 'Partial<MyClass>'.
    Object literal may only specify known properties, and 'wrong' does not exist in type 'Partial<MyClass>'

    The only thing this constructor does is create an instance and call the initialize method on it, forwarding the first argument. The customization of instance is supposed to be performed in that method.

    Type parameters

    Parameters

    • this: T
    • Optional props: Partial<InstanceType<T>>

    Returns InstanceType<T>

Generated using TypeDoc