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

@ -24,6 +24,7 @@ export class IndexedDBService {
private static readonly SYNC_STATE_STORE = 'syncState';
private db: IDBDatabase | null = null;
private initialized: boolean = false;
/**
* Initialize and open the database
@ -38,6 +39,7 @@ export class IndexedDBService {
request.onsuccess = () => {
this.db = request.result;
this.initialized = true;
resolve();
};
@ -66,6 +68,13 @@ export class IndexedDBService {
});
}
/**
* Check if database is initialized
*/
public isInitialized(): boolean {
return this.initialized;
}
/**
* Ensure database is initialized
*/