managarten/apps/context/apps/mobile/utils/eventEmitter.ts
Till-JS bb0e0cf5cb 🚚 feat(context): integrate context app into monorepo
Restructure the context app (formerly basetext) to follow the monorepo
pattern with proper workspace configuration.

Changes:
- Move app files to apps/context/apps/mobile/
- Rename package to @context/mobile
- Update bundle ID to com.manacore.context
- Create pnpm-workspace.yaml for project workspace
- Add dev scripts to root package.json
- Update CLAUDE.md with project documentation

The app structure is prepared for future web/backend additions.

Note: Existing TypeScript errors in the original codebase are preserved.
These should be fixed in a follow-up PR.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05 15:09:04 +01:00

40 lines
1,011 B
TypeScript

// Einfacher Event-Emitter für die App
type EventCallback = (...args: any[]) => void;
class EventEmitter {
private events: Record<string, EventCallback[]> = {};
// Event registrieren
on(event: string, callback: EventCallback): void {
if (!this.events[event]) {
this.events[event] = [];
}
this.events[event].push(callback);
}
// Event deregistrieren
off(event: string, callback: EventCallback): void {
if (!this.events[event]) return;
this.events[event] = this.events[event].filter((cb) => cb !== callback);
}
// Event auslösen
emit(event: string, ...args: any[]): void {
if (!this.events[event]) return;
this.events[event].forEach((callback) => {
try {
callback(...args);
} catch (error) {
console.error(`Fehler beim Ausführen des Event-Handlers für ${event}:`, error);
}
});
}
}
// Singleton-Instanz
export const eventEmitter = new EventEmitter();
// Event-Namen als Konstanten
export const EVENTS = {
TOKEN_BALANCE_UPDATED: 'TOKEN_BALANCE_UPDATED',
};