The Event is something that happened in the domain.
One Event or many Events are the result of the command execution in an Aggregate and each can cause a state change in the Aggregate. They are immutable objects, because they represent undeniable facts. The storage of Events is organized an Event Stream, each stream contains all Events of an Aggregate.
Event Attributes:
Name
The Name is used to name the EventClass and forms the Event name.
For more details, see Naming.
Schema
The properties of the Event Payload are planned with the Codebricks Planner.
For more details, see Schema.
Value Sources
The Event Schema Property Value Sources define how each property is initialized.
For more details, see Data Flow.
An example event class is located at: Task/src/shared/domain/events/TaskAddedEvent.ts
1import { Event } from "@codebricks/typebricks";23export interface TaskAddedEventProperties {4 id: string;5 aggregateId: string;6 aggregateVersion: number;7 payload: TaskAddedEventPayload;8 occurredAt: Date;9}1011export interface TaskAddedEventPayload {12 title: string;13 description: string;14 assigneeId: string;15}1617export class TaskAddedEvent extends Event<TaskAddedEventPayload> {18 static readonly eventName: string = 'TaskAdded';1920 constructor(properties: TaskAddedEventProperties) {21 super({...properties, name: TaskAddedEvent.eventName});22 }23}
This interface defines the properties of the TaskAddedEvent
.
1export interface TaskAddedEventProperties {2 id: string;3 aggregateId: string;4 aggregateVersion: number;5 payload: TaskAddedEventPayload;6 occurredAt: Date;7}
This interface defines the payload structure for the TaskAddedEvent
.
1export interface TaskAddedEventPayload {2 title: string;3 description: string;4 assigneeId: string;5}
The TaskAddedEvent
class extends the base Event
class provided by the Codebricks framework.
1import { Event } from "@codebricks/codebricks-framework";23export class TaskAddedEvent extends Event<TaskAddedEventPayload> {4 static readonly eventName: string = 'TaskAdded';56 constructor(properties: TaskAddedEventProperties) {7 super({...properties, name: TaskAddedEvent.eventName});8 }9}
eventName
property ensures the event is named consistently.