Refactor offline-first architecture with IndexedDB

Improves dependency injection and service initialization for IndexedDB-based calendar application

Implements lazy initialization for IndexedDB
Fixes race conditions in async event handling
Adds proper dependency injection with registerType
Enhances sync manager and repository pattern

Key improvements:
- Lazy database initialization
- Proper service lifecycle management
- Improved network awareness for sync operations
- Cleaned up initialization logic in index.ts
This commit is contained in:
Janus C. H. Knudsen 2025-11-05 20:35:21 +01:00
parent e7011526e3
commit a1bee99d8e
6 changed files with 226 additions and 34 deletions

View file

@ -23,8 +23,15 @@ export class IndexedDBEventRepository implements IEventRepository {
/**
* Load all events from IndexedDB
* Ensures IndexedDB is initialized and seeded on first call
*/
async loadEvents(): Promise<ICalendarEvent[]> {
// Lazy initialization on first data load
if (!this.indexedDB.isInitialized()) {
await this.indexedDB.initialize();
await this.indexedDB.seedIfEmpty();
}
return await this.indexedDB.getAllEvents();
}