Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Aggregate<S, E>

This is the aggregate interface

example
export interface Counter extends Aggregate<CounterState, CounterEvents> {
  init(counterId: string, initialCount: number): Outcome;
  count(number: number): Outcome;
  reset(): Outcome;
}

Type parameters

Hierarchy

  • Aggregate

Index

Methods

addEvent

  • Parameters

    • events: E

      The event you want to apply and add to the list of events that are not commited yet.

    Returns Outcome

apply

  • Parameters

    • events: Event | Event[]

      The event you want to apply to the current state. This function is used when you want to rehydrate your aggregate from your events store events.

    Returns ApplyEventOutcome

eventsCommited

  • eventsCommited(): void
  • Call this function clear the uncommmited events array after you saved them in your event store / repository.

    Returns void

getCommandId

  • getCommandId(): string
  • Returns string

    The current commandId of your aggregate.

getSequence

  • getSequence(): number
  • Returns number

    The current sequence of your aggregate.

getSnapshot

  • getSnapshot(): S[]

getUncommmitedEvents

  • getUncommmitedEvents(): E[]
  • Returns E[]

    The list of events you added that need to be persisted in your event store. Call eventsCommited() when it's done to clear the array.

snapshot

  • snapshot(): S
  • Returns S

    a snapshot (deep copy) of the current state.

snapshotsCommited

  • snapshotsCommited(): void

state

  • state(): S
  • Returns S

    The current state of you aggregate. Beware it's not a deep copy so if you mutate it. It will impact your aggregate state. It should never be used outside of you aggregate boundaries.

Generated using TypeDoc