Open cer opened 8 years ago
One problem with this design is that the events being handled have no relationship with the events being subscribed to
const subscriptions = [
{
subscriberId: 'todo-list-todoAggregate',
entityTypesAndEvents: todoEntityTypesAndEvents <<<===
},
{
vs.
Whatever getEventHandler knows how to process.
getEventHandler should tell Subscriber what to subscribe to.
@dartvandru @dartandrevinsky
One possibility is an event handler looks like this:
export const eventHandlers = {
[TodoAggregate] : {
[todoCreatedEvent] : handleTodoCreatedEvent,
[todoDeletedEvent] : handleTodoDeletedEvent,
[todoUpdatedEvent] : handleTodoUpdatedEvent,
[todoDeletionRequestedEvent]: handleTodoDeletionRequestedEvent
}
};
In other words its a nested map: aggregate -> aggregateEvent -> eventHandler
The high-level subscription API looks something like this:
const subscriber = new Subscriber(eventuateClient); // Rename -> SubscriptionManager?
// Do this one or more times:
subscriber.subscribe(eventHandlers)
@dartvandru I think the subscription API is still not quite right
const dispatcher = new EventDispatcher({ eventHandlers: todoBulkDeleteAggregateEventHandlers });
const subscriber = new SubscriptionManager({ eventuateClient, dispatcher });
subscriber.subscribe({ subscriberId: 'todo-list-todoBulkDeleteAggregate', eventHandlers: todoBulkDeleteAggregateEventHandlers });
It should really be something like this. First, create a global SubscriptionManager:
const subscriptionManager = new EventuateSubscriptionManager({ eventuateClient });
And then call subscribe() one or more times.
subscriptionManager.subscribe({ subscriberId: 'todo-list-todoBulkDeleteAggregate',
eventHandlers: todoBulkDeleteAggregateEventHandlers });
Internally, subscribe() can create a EventDispatcher etc but that should not be part of the API.
The developer should not need to write this.