Skip to main content

Recipes

One-shot subscriptions

QGlobalEventBus.once<{ userId: number }>('user.created', ({ userId }) => {
console.log('Fired once for user:', userId);
});

Inspect active subscriptions

const active = QGlobalEventBus.events(); // ['user.created', 'order.placed']

Remove handlers

QGlobalEventBus.off('user.created'); // remove handlers for one event
QGlobalEventBus.off(); // remove all handlers

Isolated bus for tests or scoped modules

import { QEventBus } from '@quik/events';

const bus = new QEventBus();
bus.on('local.event', () => { /* … */ });

Checklist

  • Call EventsModule.setup() once during bootstrap so subscriptions clear on onReset.
  • Prefer QGlobalEventBus for cross-service communication; use a dedicated QEventBus instance when isolation matters (tests, per-tenant scopes).