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:
parent
e7011526e3
commit
a1bee99d8e
6 changed files with 226 additions and 34 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { ICalendarEvent } from '../types/CalendarTypes';
|
||||
import { Configuration } from '../configurations/CalendarConfig';
|
||||
|
||||
/**
|
||||
* ApiEventRepository
|
||||
|
|
@ -15,8 +16,8 @@ import { ICalendarEvent } from '../types/CalendarTypes';
|
|||
export class ApiEventRepository {
|
||||
private apiEndpoint: string;
|
||||
|
||||
constructor(apiEndpoint: string) {
|
||||
this.apiEndpoint = apiEndpoint;
|
||||
constructor(config: Configuration) {
|
||||
this.apiEndpoint = config.apiEndpoint || '/api';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue