Event Bus (HookSystem)
The HookSystem is the primary mechanism for cross-module communication in the Nexical Ecosystem. It allows modules to publish events and subscribe to actions without direct coupling.
API Reference
Section titled “API Reference”HookSystem.dispatch(event, data, context?)
Section titled “HookSystem.dispatch(event, data, context?)”Fire and forget event. Useful for asynchronous side effects (e.g., sending an email after registration).
import { HookSystem } from '@/lib/modules/hooks';
// Dispatching an eventawait HookSystem.dispatch('user.registered', { userId: '123' });HookSystem.on(event, handler)
Section titled “HookSystem.on(event, handler)”Subscribe to an event. Handlers are executed in parallel when dispatched.
// Listening to an eventHookSystem.on('user.registered', async (data) => { console.log(`User registered: ${data.userId}`);});HookSystem.filter(event, data, context?)
Section titled “HookSystem.filter(event, data, context?)”Pass data through a chain of listeners, allowing each to modify it. Useful for plugins that need to enrich data or enforce policy.
// Applying filtersconst enrichedUser = await HookSystem.filter('user.view', userFromDb);// Registering a filterHookSystem.on('user.view', (user) => { return { ...user, canAccessPro: true };});