Refactors calendar initialization with factory
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.
This commit is contained in:
parent
32ee35eb02
commit
26f0cb8aaa
11 changed files with 333 additions and 150 deletions
60
src/index.ts
60
src/index.ts
|
|
@ -1,29 +1,14 @@
|
|||
// Main entry point for Calendar Plantempus
|
||||
import { eventBus } from './core/EventBus.js';
|
||||
import { CalendarManager } from './managers/CalendarManager.js';
|
||||
import { NavigationManager } from './managers/NavigationManager.js';
|
||||
import { ViewManager } from './managers/ViewManager.js';
|
||||
import { EventManager } from './managers/EventManager.js';
|
||||
import { EventRenderer } from './renderers/EventRendererManager.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';
|
||||
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 simple coordination...');
|
||||
|
||||
// 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;
|
||||
console.log('🗓️ Initializing Calendar Plantempus with factory pattern...');
|
||||
|
||||
try {
|
||||
// Use the singleton calendar configuration
|
||||
|
|
@ -33,46 +18,29 @@ async function initializeCalendar(): Promise<void> {
|
|||
console.log('🏭 Initializing CalendarTypeFactory...');
|
||||
CalendarTypeFactory.initialize();
|
||||
|
||||
// Create all managers
|
||||
console.log('📋 Creating managers...');
|
||||
calendarManager = new CalendarManager(eventBus, config);
|
||||
navigationManager = new NavigationManager(eventBus); // No EventRenderer dependency
|
||||
viewManager = new ViewManager(eventBus);
|
||||
eventManager = new EventManager(eventBus);
|
||||
eventRenderer = new EventRenderer(eventBus, eventManager); // Pass EventManager
|
||||
gridManager = new GridManager();
|
||||
scrollManager = new ScrollManager();
|
||||
|
||||
// Set manager references in CalendarManager
|
||||
calendarManager.setManagers(eventManager, gridManager, eventRenderer, scrollManager);
|
||||
// Create managers using factory pattern
|
||||
const managerFactory = ManagerFactory.getInstance();
|
||||
const managers = managerFactory.createManagers(eventBus, config);
|
||||
|
||||
// Enable debug mode for development
|
||||
eventBus.setDebug(true);
|
||||
|
||||
// Initialize using simple direct calls
|
||||
console.log('🚀 Starting simple initialization...');
|
||||
await calendarManager.initialize();
|
||||
// Initialize all managers
|
||||
await managerFactory.initializeManagers(managers);
|
||||
|
||||
console.log('🎊 Calendar Plantempus initialized successfully!');
|
||||
console.log('📊 Initialization Report:', calendarManager.getInitializationReport());
|
||||
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);
|
||||
// Could implement fallback or retry logic here
|
||||
throw error;
|
||||
}
|
||||
|
||||
// Expose to window for debugging
|
||||
(window as any).calendarDebug = {
|
||||
eventBus,
|
||||
calendarManager,
|
||||
navigationManager,
|
||||
viewManager,
|
||||
eventManager,
|
||||
eventRenderer,
|
||||
gridManager,
|
||||
scrollManager
|
||||
};
|
||||
}
|
||||
|
||||
// Initialize when DOM is ready - now handles async properly
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue