Quik Framework :: Events
- Codename: Berlin
- Version: 0.2.0-beta.76
- License: Check license here
Typed in-process domain event bus. Services can publish and subscribe to named events without direct imports. Errors thrown by individual handlers are caught and logged so they cannot break other subscribers or the emitter.
Installation
pnpm add @quik/events
Usage
Subscribe and emit
import { QGlobalEventBus } from '@quik/events';
// Subscribe — returns an unsubscribe function
const off = QGlobalEventBus.on<{ userId: number }>('user.created', async ({ userId }) => {
console.log('New user:', userId);
});
// One-shot subscription
QGlobalEventBus.once<{ userId: number }>('user.created', ({ userId }) => {
console.log('Fired once for user:', userId);
});
// Emit
await QGlobalEventBus.emit('user.created', { userId: 42 });
// Unsubscribe
off();
// Remove all handlers for an event
QGlobalEventBus.off('user.created');
// Remove all handlers
QGlobalEventBus.off();
List active events
const active = QGlobalEventBus.events(); // ['user.created', 'order.placed']
Module setup
Call Module.setup() during bootstrap. The module registers an onReset
hook that clears all subscriptions when the application resets.
import { Module as EventsModule } from '@quik/events';
await EventsModule.setup({ /* bootstrap options */ });
API Highlights
QGlobalEventBus.on<T>(event, handler)— subscribe; returns an unsubscribe function.QGlobalEventBus.once<T>(event, handler)— subscribe for a single emission; returns an unsubscribe function.QGlobalEventBus.emit<T>(event, payload)— fire all handlers in registration order; errors per handler are isolated.QGlobalEventBus.off(event?)— remove handlers for a specific event or all events.QGlobalEventBus.events()— list events that currently have at least one handler.QEventBus— class backingQGlobalEventBus; instantiate directly when you need isolated buses.
Testing & Coverage
See the root instructions for details on running pnpm run test:coverage and accessing coverage artifacts.
API Reference
Generated API documentation is available in the events API section.