Skip to main content

electron/events/TypedEventBus

Type-safe event bus with middleware support and debugging capabilities.

Remarks

Enhances the standard Node.js EventEmitter with compile-time type safety, middleware processing, correlation tracking, and comprehensive logging. Ensures events are properly typed and provides rich debugging information.

Example

import { logger } from "../utils/logger";

interface MyEvents {
"user:login": { userId: string; timestamp: number };
"data:updated": { table: string; records: number };
}

const bus = new TypedEventBus<MyEvents>("app-events");
bus.onTyped("user:login", (data) => {
logger.info("User login", data);
});
await bus.emitTyped("user:login", {
userId: "123",
timestamp: Date.now(),
});

Classes

Interfaces

Type Aliases

Variables

Functions