Major refactorering to get a hold on all these events
This commit is contained in:
parent
2a766cf685
commit
59b3c64c55
18 changed files with 1901 additions and 357 deletions
83
src/index.ts
83
src/index.ts
|
|
@ -8,32 +8,61 @@ import { EventRenderer } from './managers/EventRenderer.js';
|
|||
import { GridManager } from './managers/GridManager.js';
|
||||
import { ScrollManager } from './managers/ScrollManager.js';
|
||||
import { calendarConfig } from './core/CalendarConfig.js';
|
||||
import { CalendarTypeFactory } from './factories/CalendarTypeFactory.js';
|
||||
|
||||
/**
|
||||
* Initialize the calendar application
|
||||
* Initialize the calendar application with new state-driven approach
|
||||
*/
|
||||
function initializeCalendar(): void {
|
||||
console.log('🗓️ Initializing Calendar Plantempus...');
|
||||
async function initializeCalendar(): Promise<void> {
|
||||
console.log('🗓️ Initializing Calendar Plantempus with state management...');
|
||||
|
||||
// Use the singleton calendar configuration
|
||||
const config = calendarConfig;
|
||||
// Declare managers outside try block for global access
|
||||
let calendarManager: CalendarManager;
|
||||
let navigationManager: NavigationManager;
|
||||
let viewManager: ViewManager;
|
||||
let eventManager: EventManager;
|
||||
let eventRenderer: EventRenderer;
|
||||
let gridManager: GridManager;
|
||||
let scrollManager: ScrollManager;
|
||||
|
||||
// Initialize managers
|
||||
const calendarManager = new CalendarManager(eventBus, config);
|
||||
const navigationManager = new NavigationManager(eventBus);
|
||||
const viewManager = new ViewManager(eventBus);
|
||||
const eventManager = new EventManager(eventBus);
|
||||
const eventRenderer = new EventRenderer(eventBus);
|
||||
const scrollManager = new ScrollManager(); // Initialize BEFORE GridManager
|
||||
const gridManager = new GridManager();
|
||||
|
||||
// Enable debug mode for development
|
||||
eventBus.setDebug(true);
|
||||
|
||||
// Initialize all managers
|
||||
calendarManager.initialize();
|
||||
|
||||
console.log('✅ Calendar Plantempus initialized successfully with all core managers');
|
||||
try {
|
||||
// Use the singleton calendar configuration
|
||||
const config = calendarConfig;
|
||||
|
||||
// Initialize the CalendarTypeFactory before creating managers
|
||||
console.log('🏭 Phase 0: Initializing CalendarTypeFactory...');
|
||||
CalendarTypeFactory.initialize();
|
||||
|
||||
// Initialize managers in proper order
|
||||
console.log('📋 Phase 1: Creating core managers...');
|
||||
calendarManager = new CalendarManager(eventBus, config);
|
||||
navigationManager = new NavigationManager(eventBus);
|
||||
viewManager = new ViewManager(eventBus);
|
||||
|
||||
console.log('🎯 Phase 2: Creating data and rendering managers...');
|
||||
// These managers will now respond to state-driven events
|
||||
eventManager = new EventManager(eventBus);
|
||||
eventRenderer = new EventRenderer(eventBus);
|
||||
|
||||
console.log('🏗️ Phase 3: Creating layout managers...');
|
||||
scrollManager = new ScrollManager(); // Will respond to GRID_RENDERED
|
||||
gridManager = new GridManager(); // Will respond to RENDERING_STARTED
|
||||
|
||||
// Enable debug mode for development
|
||||
eventBus.setDebug(true);
|
||||
|
||||
// Initialize all managers using state-driven coordination
|
||||
console.log('🚀 Phase 4: Starting state-driven initialization...');
|
||||
await calendarManager.initialize(); // Now async and fully coordinated
|
||||
|
||||
console.log('🎊 Calendar Plantempus initialized successfully!');
|
||||
console.log('📊 Initialization Report:', calendarManager.getInitializationReport());
|
||||
|
||||
} catch (error) {
|
||||
console.error('💥 Calendar initialization failed:', error);
|
||||
// Could implement fallback or retry logic here
|
||||
throw error;
|
||||
}
|
||||
|
||||
// Expose to window for debugging
|
||||
(window as any).calendarDebug = {
|
||||
|
|
@ -48,9 +77,15 @@ function initializeCalendar(): void {
|
|||
};
|
||||
}
|
||||
|
||||
// Initialize when DOM is ready
|
||||
// Initialize when DOM is ready - now handles async properly
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', initializeCalendar);
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
initializeCalendar().catch(error => {
|
||||
console.error('Failed to initialize calendar:', error);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
initializeCalendar();
|
||||
initializeCalendar().catch(error => {
|
||||
console.error('Failed to initialize calendar:', error);
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue