= { - [K in keyof P]: EventPayloadObject & { - /* prohibit the type attribute on the highest layer (used to identify the event type) */ - type?: never - } -}; - -export type Event
, T extends keyof P> = {
- readonly type: T,
-
- as(target: S) : Event
;
- asUnchecked(target: S) : Event
;
- asAnyUnchecked(target: S) : Event
; - - /** - * Return an object containing only the event payload specific key value pairs. - */ - extractPayload() : P[T]; -} & P[T]; - -namespace EventHelper { - /** - * Turn the payload object into a bus event object - * @param payload - */ - /* May inline this somehow? A function call seems to be 3% slower */ - export function createEvent
, T extends keyof P>(type: T, payload?: P[T]) : Event
{ - if(payload) { - (payload as any).type = type; - let event = payload as any as Event
;
- event.as = as;
- event.asUnchecked = asUnchecked;
- event.asAnyUnchecked = asUnchecked;
- event.extractPayload = extractPayload;
- return event;
- } else {
- return {
- type,
- as,
- asUnchecked,
- asAnyUnchecked: asUnchecked,
- extractPayload
- } as any;
- }
+setEventRegistryHooks(new class implements EventRegistryHooks {
+ logAsyncInvokeError(error: any) {
+ logError(LogCategory.EVENT_REGISTRY, tr("Failed to invoke async callback:\n%o"), error);
}
- function extractPayload() {
- const result = Object.assign({}, this);
- delete result["as"];
- delete result["asUnchecked"];
- delete result["asAnyUnchecked"];
- delete result["extractPayload"];
- return result;
+ logReactInvokeError(error: any) {
+ logError(LogCategory.EVENT_REGISTRY, tr("Failed to invoke react callback:\n%o"), error);
}
- function as(target) {
- if(this.type !== target) {
- throw "Mismatching event type. Expected: " + target + ", Got: " + this.type;
- }
-
- return this;
+ logTrace(message: string, ...args: any[]) {
+ logTrace(LogCategory.EVENT_REGISTRY, message, ...args);
}
-
- function asUnchecked() {
- return this;
- }
-}
-
-export interface EventSender
please wait