Refactors calendar architecture for month view
Prepares the calendar component for month view implementation by introducing a strategy pattern for view management, splitting configuration settings, and consolidating events into a core set. It also removes dead code and enforces type safety, improving overall code quality and maintainability. Addresses critical issues identified in the code review, laying the groundwork for efficient feature addition.
This commit is contained in:
parent
7d513600d8
commit
3ddc6352f2
17 changed files with 1347 additions and 428 deletions
|
|
@ -1,170 +0,0 @@
|
|||
// Calendar state management types
|
||||
|
||||
/**
|
||||
* Calendar initialization and runtime states
|
||||
* Represents the progression from startup to ready state
|
||||
*/
|
||||
export enum CalendarState {
|
||||
UNINITIALIZED = 'uninitialized',
|
||||
INITIALIZING = 'initializing',
|
||||
CONFIG_LOADED = 'config_loaded',
|
||||
DATA_LOADING = 'data_loading',
|
||||
DATA_LOADED = 'data_loaded',
|
||||
RENDERING = 'rendering',
|
||||
RENDERED = 'rendered',
|
||||
READY = 'ready',
|
||||
ERROR = 'error'
|
||||
}
|
||||
|
||||
/**
|
||||
* State-driven events with clear progression and timing
|
||||
*/
|
||||
export const StateEvents = {
|
||||
// Core lifecycle events
|
||||
CALENDAR_STATE_CHANGED: 'calendar:state:changed',
|
||||
|
||||
// Configuration phase
|
||||
CONFIG_LOADING_STARTED: 'calendar:config:loading:started',
|
||||
CONFIG_LOADED: 'calendar:config:loaded',
|
||||
CONFIG_FAILED: 'calendar:config:failed',
|
||||
|
||||
// Data loading phase (can run parallel with rendering setup)
|
||||
DATA_LOADING_STARTED: 'calendar:data:loading:started',
|
||||
DATA_LOADED: 'calendar:data:loaded',
|
||||
DATA_FAILED: 'calendar:data:failed',
|
||||
|
||||
// Rendering phase
|
||||
RENDERING_STARTED: 'calendar:rendering:started',
|
||||
DOM_STRUCTURE_READY: 'calendar:dom:structure:ready',
|
||||
GRID_RENDERED: 'calendar:grid:rendered',
|
||||
EVENTS_RENDERED: 'calendar:events:rendered',
|
||||
RENDERING_COMPLETE: 'calendar:rendering:complete',
|
||||
|
||||
// System ready
|
||||
CALENDAR_READY: 'calendar:ready',
|
||||
|
||||
// Error handling
|
||||
CALENDAR_ERROR: 'calendar:error',
|
||||
RECOVERY_ATTEMPTED: 'calendar:recovery:attempted',
|
||||
RECOVERY_SUCCESS: 'calendar:recovery:success',
|
||||
RECOVERY_FAILED: 'calendar:recovery:failed',
|
||||
|
||||
// User interaction events (unchanged)
|
||||
VIEW_CHANGE_REQUESTED: 'calendar:view:change:requested',
|
||||
VIEW_CHANGED: 'calendar:view:changed',
|
||||
NAVIGATION_REQUESTED: 'calendar:navigation:requested',
|
||||
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* Standardized event payload structure
|
||||
*/
|
||||
export interface CalendarEvent {
|
||||
type: string;
|
||||
component: string;
|
||||
timestamp: number;
|
||||
data?: any;
|
||||
error?: Error;
|
||||
metadata?: {
|
||||
duration?: number;
|
||||
dependencies?: string[];
|
||||
phase?: string;
|
||||
retryCount?: number;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* State change event payload
|
||||
*/
|
||||
export interface StateChangeEvent extends CalendarEvent {
|
||||
type: typeof StateEvents.CALENDAR_STATE_CHANGED;
|
||||
data: {
|
||||
from: CalendarState;
|
||||
to: CalendarState;
|
||||
transitionValid: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Error event payload
|
||||
*/
|
||||
export interface ErrorEvent extends CalendarEvent {
|
||||
type: typeof StateEvents.CALENDAR_ERROR;
|
||||
error: Error;
|
||||
data: {
|
||||
failedComponent: string;
|
||||
currentState: CalendarState;
|
||||
canRecover: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Data loaded event payload
|
||||
*/
|
||||
export interface DataLoadedEvent extends CalendarEvent {
|
||||
type: typeof StateEvents.DATA_LOADED;
|
||||
data: {
|
||||
eventCount: number;
|
||||
calendarMode: 'date' | 'resource';
|
||||
period: {
|
||||
start: string;
|
||||
end: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Grid rendered event payload
|
||||
*/
|
||||
export interface GridRenderedEvent extends CalendarEvent {
|
||||
type: typeof StateEvents.GRID_RENDERED;
|
||||
data: {
|
||||
columnCount: number;
|
||||
rowCount?: number;
|
||||
gridMode: 'date' | 'resource';
|
||||
domElementsCreated: string[];
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Valid state transitions map
|
||||
* Defines which state transitions are allowed
|
||||
*/
|
||||
export const VALID_STATE_TRANSITIONS: Record<CalendarState, CalendarState[]> = {
|
||||
[CalendarState.UNINITIALIZED]: [CalendarState.INITIALIZING, CalendarState.ERROR],
|
||||
[CalendarState.INITIALIZING]: [CalendarState.CONFIG_LOADED, CalendarState.ERROR],
|
||||
[CalendarState.CONFIG_LOADED]: [CalendarState.DATA_LOADING, CalendarState.RENDERING, CalendarState.ERROR],
|
||||
[CalendarState.DATA_LOADING]: [CalendarState.DATA_LOADED, CalendarState.ERROR],
|
||||
[CalendarState.DATA_LOADED]: [CalendarState.RENDERING, CalendarState.RENDERED, CalendarState.ERROR],
|
||||
[CalendarState.RENDERING]: [CalendarState.RENDERED, CalendarState.ERROR],
|
||||
[CalendarState.RENDERED]: [CalendarState.READY, CalendarState.ERROR],
|
||||
[CalendarState.READY]: [CalendarState.DATA_LOADING, CalendarState.ERROR], // Allow refresh
|
||||
[CalendarState.ERROR]: [CalendarState.INITIALIZING, CalendarState.CONFIG_LOADED] // Recovery paths
|
||||
};
|
||||
|
||||
/**
|
||||
* State phases for logical grouping
|
||||
*/
|
||||
export enum InitializationPhase {
|
||||
STARTUP = 'startup',
|
||||
CONFIGURATION = 'configuration',
|
||||
DATA_AND_DOM = 'data-and-dom',
|
||||
EVENT_RENDERING = 'event-rendering',
|
||||
FINALIZATION = 'finalization',
|
||||
ERROR_RECOVERY = 'error-recovery'
|
||||
}
|
||||
|
||||
/**
|
||||
* Map states to their initialization phases
|
||||
*/
|
||||
export const STATE_TO_PHASE: Record<CalendarState, InitializationPhase> = {
|
||||
[CalendarState.UNINITIALIZED]: InitializationPhase.STARTUP,
|
||||
[CalendarState.INITIALIZING]: InitializationPhase.STARTUP,
|
||||
[CalendarState.CONFIG_LOADED]: InitializationPhase.CONFIGURATION,
|
||||
[CalendarState.DATA_LOADING]: InitializationPhase.DATA_AND_DOM,
|
||||
[CalendarState.DATA_LOADED]: InitializationPhase.DATA_AND_DOM,
|
||||
[CalendarState.RENDERING]: InitializationPhase.DATA_AND_DOM,
|
||||
[CalendarState.RENDERED]: InitializationPhase.EVENT_RENDERING,
|
||||
[CalendarState.READY]: InitializationPhase.FINALIZATION,
|
||||
[CalendarState.ERROR]: InitializationPhase.ERROR_RECOVERY
|
||||
};
|
||||
33
src/types/EventTypes.ts
Normal file
33
src/types/EventTypes.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
* Type definitions for calendar events
|
||||
*/
|
||||
|
||||
export interface AllDayEvent {
|
||||
id: string;
|
||||
title: string;
|
||||
start: Date | string;
|
||||
end: Date | string;
|
||||
allDay: true;
|
||||
color?: string;
|
||||
metadata?: {
|
||||
color?: string;
|
||||
category?: string;
|
||||
location?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface TimeEvent {
|
||||
id: string;
|
||||
title: string;
|
||||
start: Date | string;
|
||||
end: Date | string;
|
||||
allDay?: false;
|
||||
color?: string;
|
||||
metadata?: {
|
||||
color?: string;
|
||||
category?: string;
|
||||
location?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export type CalendarEventData = AllDayEvent | TimeEvent;
|
||||
Loading…
Add table
Add a link
Reference in a new issue