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.
133 lines
No EOL
3.8 KiB
Markdown
133 lines
No EOL
3.8 KiB
Markdown
# Calendar Initialization Sequence Diagram
|
|
|
|
Dette diagram viser den aktuelle initialization sekvens baseret på koden.
|
|
|
|
```mermaid
|
|
sequenceDiagram
|
|
participant Browser
|
|
participant Index as index.ts
|
|
participant MF as ManagerFactory
|
|
participant CTF as CalendarTypeFactory
|
|
participant EB as EventBus
|
|
participant CM as CalendarManager
|
|
participant EM as EventManager
|
|
participant ERS as EventRenderingService
|
|
participant GM as GridManager
|
|
participant GSM as GridStyleManager
|
|
participant GR as GridRenderer
|
|
participant SM as ScrollManager
|
|
participant NM as NavigationManager
|
|
participant NR as NavigationRenderer
|
|
participant VM as ViewManager
|
|
|
|
Browser->>Index: DOMContentLoaded
|
|
Index->>Index: initializeCalendar()
|
|
|
|
Index->>CTF: initialize()
|
|
CTF-->>Index: Factory ready
|
|
|
|
Index->>MF: getInstance()
|
|
MF-->>Index: Factory instance
|
|
|
|
Index->>MF: createManagers(eventBus, config)
|
|
|
|
MF->>EM: new EventManager(eventBus)
|
|
EM->>EB: setupEventListeners()
|
|
EM-->>MF: EventManager ready
|
|
|
|
MF->>ERS: new EventRenderingService(eventBus, eventManager)
|
|
ERS->>EB: setupEventListeners()
|
|
ERS-->>MF: EventRenderingService ready
|
|
|
|
MF->>GM: new GridManager()
|
|
GM->>GSM: new GridStyleManager(config)
|
|
GM->>GR: new GridRenderer(config)
|
|
GM->>EB: subscribeToEvents()
|
|
GM-->>MF: GridManager ready
|
|
|
|
MF->>SM: new ScrollManager()
|
|
SM->>EB: subscribeToEvents()
|
|
SM-->>MF: ScrollManager ready
|
|
|
|
MF->>NM: new NavigationManager(eventBus)
|
|
NM->>NR: new NavigationRenderer(eventBus)
|
|
NR->>EB: setupEventListeners()
|
|
NM->>EB: setupEventListeners()
|
|
NM-->>MF: NavigationManager ready
|
|
|
|
MF->>VM: new ViewManager(eventBus)
|
|
VM->>EB: setupEventListeners()
|
|
VM-->>MF: ViewManager ready
|
|
|
|
MF->>CM: new CalendarManager(eventBus, config, deps...)
|
|
CM->>EB: setupEventListeners()
|
|
CM-->>MF: CalendarManager ready
|
|
|
|
MF-->>Index: All managers created
|
|
|
|
Index->>EB: setDebug(true)
|
|
Index->>MF: initializeManagers(managers)
|
|
MF->>CM: initialize()
|
|
|
|
CM->>EM: loadData()
|
|
EM->>EM: loadMockData()
|
|
EM->>EM: processCalendarData()
|
|
EM-->>CM: Data loaded
|
|
|
|
CM->>GM: setResourceData(resourceData)
|
|
GM-->>CM: Resource data set
|
|
|
|
CM->>GM: render()
|
|
GM->>GSM: updateGridStyles(resourceData)
|
|
GM->>GR: renderGrid(grid, currentWeek, resourceData, allDayEvents)
|
|
GR-->>GM: Grid rendered
|
|
|
|
GM->>EB: emit(GRID_RENDERED, context)
|
|
EB-->>ERS: GRID_RENDERED event
|
|
|
|
ERS->>EM: getEventsForPeriod(startDate, endDate)
|
|
EM-->>ERS: Filtered events
|
|
ERS->>ERS: strategy.renderEvents()
|
|
|
|
CM->>SM: initialize()
|
|
SM->>SM: setupScrolling()
|
|
|
|
CM->>CM: setView(currentView)
|
|
CM->>EB: emit(VIEW_CHANGED, viewData)
|
|
|
|
CM->>CM: setCurrentDate(currentDate)
|
|
CM->>EB: emit(DATE_CHANGED, dateData)
|
|
|
|
CM->>EB: emit(CALENDAR_INITIALIZED, initData)
|
|
|
|
EB-->>NM: CALENDAR_INITIALIZED
|
|
NM->>NM: updateWeekInfo()
|
|
NM->>EB: emit(WEEK_INFO_UPDATED, weekInfo)
|
|
EB-->>NR: WEEK_INFO_UPDATED
|
|
NR->>NR: updateWeekInfoInDOM()
|
|
|
|
EB-->>VM: CALENDAR_INITIALIZED
|
|
VM->>VM: initializeView()
|
|
VM->>EB: emit(VIEW_RENDERED, viewData)
|
|
|
|
CM-->>MF: Initialization complete
|
|
MF-->>Index: All managers initialized
|
|
|
|
Index->>Browser: Calendar ready
|
|
```
|
|
|
|
## Aktuel Arkitektur Status
|
|
|
|
### Factory Pattern
|
|
- ManagerFactory håndterer manager instantiering
|
|
- Proper dependency injection via constructor
|
|
|
|
### Event-Driven Communication
|
|
- EventBus koordinerer kommunikation mellem managers
|
|
- NavigationRenderer lytter til WEEK_INFO_UPDATED events
|
|
- EventRenderingService reagerer på GRID_RENDERED events
|
|
|
|
### Separation of Concerns
|
|
- Managers håndterer business logic
|
|
- Renderers håndterer DOM manipulation
|
|
- EventBus håndterer kommunikation |