event-emitter
Events
EmitResult
Defined in: event-emitter.ts:9
Result object returned when emitting a cancellable event.
Properties
defaultPrevented
defaultPrevented: boolean;
Defined in: event-emitter.ts:20
Whether any handler called preventDefault() on the event. Only applicable if the event is cancellable.
errors
errors: Error[];
Defined in: event-emitter.ts:14
Array of errors that occurred during handler execution. Handlers continue executing even if previous handlers throw errors.
getEvents()
function getEvents(): CancellableEventEmitter;
Defined in: event-emitter.ts:149
Get the singleton event emitter instance.
Creates the instance on first call, then returns the same instance on subsequent calls. This ensures all parts of the application share the same event bus.
Returns
CancellableEventEmitter
The singleton CancellableEventEmitter instance
Example
// In generator.ts
const events = getEvents();
events.on("beforeLoadSchema", handler);
// In renderer.ts - same instance!
const events = getEvents();
await events.emitAsync("beforeLoadSchema", event);
resetEvents()
function resetEvents(): void;
Defined in: event-emitter.ts:173
Reset the event emitter singleton.
Removes all event listeners and clears the instance. The next call to getEvents() will create a fresh instance.
Important: This should only be used in tests to ensure test isolation.
Returns
void
Example
// In test setup
afterEach(() => {
resetEvents();
jest.restoreAllMocks();
});