Skip to content

Commit

Permalink
AP-4870 PR suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosGamero committed Aug 30, 2024
1 parent ff88629 commit 892cf5b
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions packages/core/lib/events/DomainEventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type DomainEventEmitterDependencies<SupportedEvents extends CommonEventDe
eventRegistry: EventRegistry<SupportedEvents>
metadataFiller: MetadataFiller
logger: Logger
errorReporter: ErrorReporter
errorReporter?: ErrorReporter
transactionObservabilityManager?: TransactionObservabilityManager
}

Expand All @@ -40,7 +40,7 @@ export class DomainEventEmitter<SupportedEvents extends CommonEventDefinition[]>
private readonly eventRegistry: EventRegistry<SupportedEvents>
private readonly metadataFiller: MetadataFiller
private readonly logger: Logger
private readonly errorReporter: ErrorReporter
private readonly errorReporter?: ErrorReporter
private readonly transactionObservabilityManager?: TransactionObservabilityManager
private readonly _handlerSpy?: HandlerSpy<
CommonEventDefinitionConsumerSchemaType<SupportedEvents[number]>
Expand Down Expand Up @@ -134,13 +134,13 @@ export class DomainEventEmitter<SupportedEvents extends CommonEventDefinition[]>
public on<EventTypeName extends EventTypeNames<SupportedEvents[number]>>(
eventTypeName: EventTypeName,
handler: SingleEventHandler<SupportedEvents, EventTypeName>,
bgHandler = false,
isBackgroundHandler = false,
) {
if (!this.eventHandlerMap[eventTypeName]) {
this.eventHandlerMap[eventTypeName] = { foreground: [], background: [] }
}

if (bgHandler) this.eventHandlerMap[eventTypeName].background.push(handler)
if (isBackgroundHandler) this.eventHandlerMap[eventTypeName].background.push(handler)
else this.eventHandlerMap[eventTypeName].foreground.push(handler)
}

Expand All @@ -150,18 +150,18 @@ export class DomainEventEmitter<SupportedEvents extends CommonEventDefinition[]>
public onMany<EventTypeName extends EventTypeNames<SupportedEvents[number]>>(
eventTypeNames: EventTypeName[],
handler: SingleEventHandler<SupportedEvents, EventTypeName>,
bgHandler = false,
isBackgroundHandler = false,
) {
for (const eventTypeName of eventTypeNames) {
this.on(eventTypeName, handler, bgHandler)
this.on(eventTypeName, handler, isBackgroundHandler)
}
}

/**
* Register handler for all events supported by the emitter
*/
public onAny(handler: AnyEventHandler<SupportedEvents>, bgHandler = false) {
if (bgHandler) this.anyHandlers.background.push(handler)
public onAny(handler: AnyEventHandler<SupportedEvents>, isBackgroundHandler = false) {
if (isBackgroundHandler) this.anyHandlers.background.push(handler)
else this.anyHandlers.foreground.push(handler)
}

Expand Down Expand Up @@ -204,7 +204,7 @@ export class DomainEventEmitter<SupportedEvents extends CommonEventDefinition[]>
...resolveGlobalErrorLogObject(error),
...context,
})
this.errorReporter.report({ error: error, context })
this.errorReporter?.report({ error: error, context })
})
}
}
Expand Down

0 comments on commit 892cf5b

Please sign in to comment.