💬 When all given handlers dispatch (and then on every event) ...
(every given EventHandler has dispatched at least one DomainEvent)
Rest
...handlers: [...Handlers[]]💬 Every time ...
(
consume().all()
means: always every EventHandler must dispatch again)
💬 unsubscribes from all listened EventHandlers and marks this combiner as destroyed.
Further chains that end with
.then(...)
will not subscribe to the given handlers and thus no listening will happen, but the extendableonLog()
method will be called withtype = 'alreadyDestroyed'
Protected
first💬 ... Just take the first occurred events from each and ...
(if an event already occurred, then it will not be overwritten by following events of the same type until the
then()
is called and the events are consumed)
Protected
on💬 Inject Logging (by extending this class)
This method is called when the
.then(...)
callback is called, the combiner is destroyed, or the callback is called, when already destroyed. The original method will do nothing. To utilize this method (eg. for a Logger integration) this class must be extended: *
class MyEventCombiner extends EventCombiner {
protected onLog(type: 'then' | 'destroy' | 'alreadyDestroyed'): void {
console.log(type, this._name, this._receivedEvents, this._eventHandlers);
}
}
💬 Always when one of the given handlers dispatches ...
(just one of the given EventHandler has dispatched a DomainEvent)
Rest
...handlers: [...Handlers[]]Protected
then💬 ... Call the given callback.
A list of all possible DomainEvents is passed to the callback, which corresponds to the order of the defined EventHandlers. *
When this method is chained with a some(...)
method, the DomainEvents may also be 'pending'
for those EventHandlers which have not dispatched yet.
Generated using TypeDoc
Combines multiple events to let subscribers listen to any combination of the events
There are 8 different combinations that can be achieved by the following chaining of the EventCombiners methods.
.all()
.once().all()
.once().all().first()
.consume().all()
.consume().all().first()
.some()
.once().some()
.consume().some()
Example
Description
Detailed overview
Consider having
new EventCombiner('myCombiner')
as a prefix for the following method chains:.all(HANDLERS).then(CALLBACK)
.some(HANDLERS).then(CALLBACK)
.once().all(HANDLERS).then(CALLBACK)
.once().all(HANDLERS).first().then(CALLBACK)
.once().some(HANDLERS).then(CALLBACK)
.consume().all(HANDLERS).then(CALLBACK)
.consume().all(HANDLERS)first().then(CALLBACK)
.consume().some(HANDLERS).then(CALLBACK)
consume()
behavior"consume" can be understood as a consumption of the dispatched events when the callback is called, so
consume()
resets the received events. This means that the payloads provided in the CALLBACK will only be the ones that have been delivered since the last call of the CALLBACK. Thereforeall()
will have all "fresh" payloads andsome()
will have only one (the last) payload.Without
consume()
the CALLBACKS will always receive the respectively last payload that has been delivered for every corresponding event - even if the event has dispatched in a previous iteration of the CALLBACK.HANDLERS
HANDLERS is a list of
EventHandler
s that one would normally subscribe separately to.CALLBACK
The CALLBACK is a function that provides the dispatched
DomainEvent
s from the given HANDLERS as an array. The order of the DomainEvents in the array correlates to the order of the given HANDLERS from theall(HANDLERS)
orsome(HANDLERS)
method. The DomainEvents including their payloads are also correctly typed corresponding to their HANDLERS.ATTENTION:
Since
some()
means that not all of the HANDLERS have to dispatch, not all of the provided DomainEvents may exist. Therefore the type isDomainEvent<any> | 'pending'
, where 'pending' means, that the EVENT has not yet been dispatched. This has to be catched when working with the.some(HANDLERS)
payloads.