feat(core): add module scaffolding and provider registries

This commit is contained in:
kyasuda
2026-02-10 13:16:01 -08:00
committed by sudacode
parent 531f8027bd
commit 09e142279a
19 changed files with 822 additions and 0 deletions

21
src/core/action-bus.ts Normal file
View File

@@ -0,0 +1,21 @@
export type ActionWithType = { type: string };
export type ActionHandler<TAction extends ActionWithType> = (
action: TAction,
) => void | Promise<void>;
export class ActionBus<TAction extends ActionWithType> {
private handlers = new Map<string, ActionHandler<TAction>>();
register(type: TAction["type"], handler: ActionHandler<TAction>): void {
this.handlers.set(type, handler);
}
async dispatch(action: TAction): Promise<void> {
const handler = this.handlers.get(action.type);
if (!handler) {
throw new Error(`No handler registered for action: ${action.type}`);
}
await handler(action);
}
}