feat(commands): add app state dispatcher foundation

This commit is contained in:
syntaxbullet
2026-07-03 09:28:06 +02:00
parent 697d12725d
commit a8dbd26474
11 changed files with 331 additions and 3 deletions

22
commands/registry.ts Normal file
View File

@@ -0,0 +1,22 @@
import type { Command } from "./command";
export type CommandRegistry = {
get(id: string): Command<unknown> | undefined;
list(): Command<unknown>[];
};
export function createCommandRegistry(commands: Command<unknown>[]): CommandRegistry {
const byId = new Map<string, Command<unknown>>();
for (const command of commands) {
if (byId.has(command.id)) {
throw new Error(`Duplicate command id: ${command.id}`);
}
byId.set(command.id, command);
}
return {
get: (id) => byId.get(id),
list: () => [...byId.values()],
};
}