Implements a factory pattern for manager creation and initialization, improving dependency management and extensibility. This change replaces direct manager instantiation with a `ManagerFactory` that handles dependency injection. This enhances code organization and testability. It also includes an initialization sequence diagram for better understanding of the calendar's architecture and data flow.
57 lines
No EOL
1.9 KiB
TypeScript
57 lines
No EOL
1.9 KiB
TypeScript
// Main entry point for Calendar Plantempus
|
|
import { eventBus } from './core/EventBus.js';
|
|
import { calendarConfig } from './core/CalendarConfig.js';
|
|
import { CalendarTypeFactory } from './factories/CalendarTypeFactory.js';
|
|
import { ManagerFactory } from './factories/ManagerFactory.js';
|
|
|
|
/**
|
|
* Initialize the calendar application with simple direct calls
|
|
*/
|
|
async function initializeCalendar(): Promise<void> {
|
|
console.log('🗓️ Initializing Calendar Plantempus with factory pattern...');
|
|
|
|
try {
|
|
// Use the singleton calendar configuration
|
|
const config = calendarConfig;
|
|
|
|
// Initialize the CalendarTypeFactory before creating managers
|
|
console.log('🏭 Initializing CalendarTypeFactory...');
|
|
CalendarTypeFactory.initialize();
|
|
|
|
// Create managers using factory pattern
|
|
const managerFactory = ManagerFactory.getInstance();
|
|
const managers = managerFactory.createManagers(eventBus, config);
|
|
|
|
// Enable debug mode for development
|
|
eventBus.setDebug(true);
|
|
|
|
// Initialize all managers
|
|
await managerFactory.initializeManagers(managers);
|
|
|
|
console.log('🎊 Calendar Plantempus initialized successfully!');
|
|
console.log('📊 Initialization Report:', managers.calendarManager.getInitializationReport());
|
|
|
|
// Expose to window for debugging
|
|
(window as any).calendarDebug = {
|
|
eventBus,
|
|
...managers
|
|
};
|
|
|
|
} catch (error) {
|
|
console.error('💥 Calendar initialization failed:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
// Initialize when DOM is ready - now handles async properly
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
initializeCalendar().catch(error => {
|
|
console.error('Failed to initialize calendar:', error);
|
|
});
|
|
});
|
|
} else {
|
|
initializeCalendar().catch(error => {
|
|
console.error('Failed to initialize calendar:', error);
|
|
});
|
|
} |