@moult/events
v0.1.2
Published
Generation-scoped typed event capability for Moult hosts and plugins.
Maintainers
Readme
@moult/events
Generation-scoped, typed events for Moult plugins and hosts.
Installation
npm install @moult/events @moult/runtimeRequires Node.js 22 or newer.
Example
Subscriptions belong to a plugin scope. Disposing that generation removes its listeners automatically.
import { createEventBus } from '@moult/events';
import { createRuntime } from '@moult/runtime';
type AppEvents = {
message: string;
count: number;
};
const runtime = createRuntime();
const bus = createEventBus<AppEvents>('sync');
runtime.install({
id: 'logger',
version: '1.0.0',
setup: (context) => {
bus.on(context.scope, 'message', (message) => {
console.log(message);
});
},
});
await runtime.start('logger');
bus.emit('message', 'hello');
await runtime.dispose(); // removes the logger subscriptionFeatures
- Event names and payloads are checked by TypeScript.
- Synchronous and asynchronous delivery modes are supported.
- Subscriber failures are isolated and reported through an optional diagnostic callback.
- Asynchronous delivery preserves order per event key.
- Subscriptions are owned by the supplied Moult scope.
eventBusFactoryandeventBusCapabilitysupport host-provided buses.
This package is an event capability, not a second lifecycle system or a global
application registry. Plugin replacement and disposal remain owned by
@moult/runtime.
Public API
The package exports createEventBus, eventBusFactory, eventBusCapability,
TypedEventCapability, EventBusFactory, EventMap, EventListener,
EventDiagnostic, and DeliveryMode.
Status and documentation
Implemented and published. See the Moult repository, the adapter design, and the lifecycle guarantees.
