Refactors event system to use CoreEvents
Migrates the application to use a new CoreEvents system. This change removes the legacy EventTypes constant file and updates all managers, renderers, and core components to use the CoreEvents constant file for event emission and subscription. This improves code maintainability and promotes a consistent eventing strategy across the application. Adds validation to EventBus emit and extractCategory functions.
This commit is contained in:
parent
414ef1caaf
commit
4b4dbdc0d6
11 changed files with 76 additions and 228 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { IEventBus } from '../types/CalendarTypes.js';
|
||||
import { EventRenderingService } from '../renderers/EventRendererManager.js';
|
||||
import { DateCalculator } from '../utils/DateCalculator.js';
|
||||
import { EventTypes } from '../constants/EventTypes.js';
|
||||
import { CoreEvents } from '../constants/CoreEvents.js';
|
||||
import { NavigationRenderer } from '../renderers/NavigationRenderer.js';
|
||||
import { calendarConfig } from '../core/CalendarConfig.js';
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ export class NavigationManager {
|
|||
|
||||
private setupEventListeners(): void {
|
||||
// Initial DOM update when calendar is initialized
|
||||
this.eventBus.on(EventTypes.CALENDAR_INITIALIZED, () => {
|
||||
this.eventBus.on(CoreEvents.CALENDAR_INITIALIZED, () => {
|
||||
console.log('NavigationManager: Received CALENDAR_INITIALIZED, updating week info');
|
||||
this.updateWeekInfo();
|
||||
});
|
||||
|
|
@ -63,7 +63,7 @@ export class NavigationManager {
|
|||
});
|
||||
|
||||
// Listen for external navigation requests
|
||||
this.eventBus.on(EventTypes.NAVIGATE_TO_DATE, (event: Event) => {
|
||||
this.eventBus.on(CoreEvents.NAVIGATE_TO_DATE, (event: Event) => {
|
||||
const customEvent = event as CustomEvent;
|
||||
const targetDate = new Date(customEvent.detail.date);
|
||||
this.navigateToDate(targetDate);
|
||||
|
|
@ -189,13 +189,13 @@ export class NavigationManager {
|
|||
|
||||
// Update week info and notify other managers
|
||||
this.updateWeekInfo();
|
||||
this.eventBus.emit(EventTypes.WEEK_CHANGED, {
|
||||
this.eventBus.emit(CoreEvents.WEEK_CHANGED, {
|
||||
weekStart: this.currentWeek,
|
||||
weekEnd: this.dateCalculator.addDays(this.currentWeek, 6)
|
||||
});
|
||||
|
||||
// Emit animation complete event for ScrollManager
|
||||
this.eventBus.emit(EventTypes.NAVIGATION_ANIMATION_COMPLETE, {
|
||||
// Emit period change event for ScrollManager
|
||||
this.eventBus.emit(CoreEvents.PERIOD_CHANGED, {
|
||||
direction,
|
||||
weekStart: this.currentWeek
|
||||
});
|
||||
|
|
@ -211,7 +211,7 @@ export class NavigationManager {
|
|||
const dateRange = this.dateCalculator.formatDateRange(this.currentWeek, weekEnd);
|
||||
|
||||
// Notify other managers about week info update - DOM manipulation should happen via events
|
||||
this.eventBus.emit(EventTypes.WEEK_INFO_UPDATED, {
|
||||
this.eventBus.emit(CoreEvents.WEEK_CHANGED, {
|
||||
weekNumber,
|
||||
dateRange,
|
||||
weekStart: this.currentWeek,
|
||||
|
|
@ -248,7 +248,7 @@ export class NavigationManager {
|
|||
this.targetWeek = new Date(weekStart);
|
||||
this.updateWeekInfo();
|
||||
|
||||
this.eventBus.emit(EventTypes.WEEK_CHANGED, {
|
||||
this.eventBus.emit(CoreEvents.WEEK_CHANGED, {
|
||||
weekStart: this.currentWeek,
|
||||
weekEnd: DateUtils.addDays(this.currentWeek, 6)
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue