/** * Lightweight State Manager for Short Track Dashboard * Replaces global variables with reactive state + event system */ class AppState { constructor() { this._state = {}; this._listeners = {}; } get(key) { return this._state[key]; } set(key, value) { const old = this._state[key]; this._state[key] = value; if (old !== value && this._listeners[key]) { this._listeners[key].forEach(fn => fn(value, old)); } } on(key, fn) { if (!this._listeners[key]) this._listeners[key] = []; this._listeners[key].push(fn); return () => { this._listeners[key] = this._listeners[key].filter(f => f !== fn); }; } batch(updates) { Object.entries(updates).forEach(([k, v]) => this.set(k, v)); } } // Global singleton const store = new AppState(); // Initialize default state store.batch({ athletes: [], selectedAthlete: null, selectedEvent: null, currentUser: null, dashboardData: null, currentMatchId: null, trainingTypes: [], profileAthlete: null, profileTab: 'overview', profileData: null, editingMessageId: null, replyingToId: null, liveRaceGroups: [], }); // Convenience: expose as global for backward compat window.store = store;