Open ryan-mars opened 3 years ago
Aggregate constructor should require the reduce
function for the ordered list of events as well as the initialValue
.
The reducer will need to know the types of events it may receive, so we will need to add events
. Adding the events to the aggregate here might simplify the EventStorm
constructor which can take a very long list of components.
export const FlightScheduleAggregate = new Aggregate({
__filename,
key: "flightNo",
shape: FlightSchedule,
events: [ ... ] // Event components for this aggregate.
reducer: (accumulator, event, index, array) => { ... },
initialValue: { ... }
});
Aggregate.Client
provided to Command's Command.Handler
(or execute
) allows you to fetch an Aggregate by its key. It should provide more than just state (after reduce
has run) it should allow access to the array of events/snapshots as well. Not sure what this should look like but some commands may need to see the list of events for handling difficult situations.
Currently it looks like this.
{
get: (key) => Promise<some shape>
}
Perhaps the return of get could be {state: ... , events: [ ... ] }
?
{
get: (key) => Promise<{ state: ... , events: [ ... ] }>
}
Thought: Commands and Domain Events mostly operate in relation to an Aggregate. Would it not make more sense to have a helper on an aggregate for declaring new Commands (setting the aggregate
prop) and new Domain Events (defaulting the source
key).
Maybe later:
Aggregate
class for declaring Commands and Events that "operate on" the aggregateIllustration ©️ Avanscoperta