Options
All
  • Public
  • Public/Protected
  • All
Menu

When writing entity classes, you can inherit from this class to write less code.

class Cat extends Entity<boolean> {
  constructor(id, decisionSequence, publish) {
    super(id, decisionSequence, publish);
  }
  public async pet() { await this.publishAndApply({ type: "pet" }); }
  protected getAggregate() { return "cat"; }
  protected getDecisionReducer() { return catFedReducer; }
}

Type parameters

  • TDecision

Hierarchy

  • Entity

Index

Constructors

constructor

  • The constructor has the same arguments that the Store provides to create an entity, which makes interfacing easy.

    Parameters

    • id: string

      the id of the entity

    • decisionSequence: DecisionSequence<TDecision>

      the current DecisionSequence (decision projection + sequence of last event)

    • publish: function

      the publish method to call when the entity wants to emit an event

        • Parameters

          • event: Event

            the event to publish

          • decisionSequence: DecisionSequence<TDecision>

            the DecisionSequence up to date with the event to publish

          Returns Promise<void>

    Returns Entity

Properties

Private decisionSequence

decisionSequence: DecisionSequence<TDecision>

the current DecisionSequence (decision projection + sequence of last event)

Private id

id: string

the id of the entity

Private publish

publish: function

the publish method to call when the entity wants to emit an event

Type declaration

Methods

Protected Abstract getAggregate

  • getAggregate(): string
  • Returns string

    the entity's aggregate

Protected getDecision

  • getDecision(): TDecision
  • Returns TDecision

    the current decision state

Protected Abstract getDecisionReducer

  • getDecisionReducer(): Reducer<TDecision>

Protected getId

  • getId(): string

Protected publishAndApply

  • publishAndApply(eventData: any): Promise<Event>
  • Call this method with only the custom event fields, it will set for you the mandatory fields, emit the event and apply it to itself to update its decision projection.

    Parameters

    • eventData: any

      the event's custom properties

    Returns Promise<Event>

    the complete event object

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc