The constructor has the same arguments that the Store provides to create an entity, which makes interfacing easy.
the id of the entity
the current DecisionSequence (decision projection + sequence of last event)
the publish method to call when the entity wants to emit an event
the event to publish
the DecisionSequence up to date with the event to publish
the current DecisionSequence (decision projection + sequence of last event)
the id of the entity
the publish method to call when the entity wants to emit an event
the entity's aggregate
the current decision state
the aggregate's decision reducer
the entity's id
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.
the event's custom properties
the complete event object
Generated using TypeDoc
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; } }