Refactors repository layer and IndexedDB architecture
Eliminates redundant repository abstraction layer by directly using EntityService methods Implements key improvements: - Removes unnecessary repository wrappers - Introduces polymorphic DataSeeder for mock data loading - Renames IndexedDBService to IndexedDBContext - Fixes database injection timing with lazy access pattern - Simplifies EventManager to use services directly Reduces code complexity and improves separation of concerns
This commit is contained in:
parent
5648c7c304
commit
dcd76836bd
10 changed files with 1260 additions and 574 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { ISync, EntityType, SyncStatus } from '../types/CalendarTypes';
|
||||
import { IEntityService } from './IEntityService';
|
||||
import { SyncPlugin } from './SyncPlugin';
|
||||
import { IndexedDBContext } from './IndexedDBContext';
|
||||
|
||||
/**
|
||||
* BaseEntityService<T extends ISync> - Abstract base class for all entity services
|
||||
|
|
@ -13,6 +14,7 @@ import { SyncPlugin } from './SyncPlugin';
|
|||
* - Generic CRUD operations (get, getAll, save, delete)
|
||||
* - Sync status management (delegates to SyncPlugin)
|
||||
* - Serialization hooks (override in subclass if needed)
|
||||
* - Lazy database access via IndexedDBContext
|
||||
*
|
||||
* SUBCLASSES MUST IMPLEMENT:
|
||||
* - storeName: string (IndexedDB object store name)
|
||||
|
|
@ -27,6 +29,7 @@ import { SyncPlugin } from './SyncPlugin';
|
|||
* - Type safety: Generic T ensures compile-time checking
|
||||
* - Pluggable: SyncPlugin can be swapped for testing/different implementations
|
||||
* - Open/Closed: New entities just extend this class
|
||||
* - Lazy database access: db requested when needed, not at construction time
|
||||
*/
|
||||
export abstract class BaseEntityService<T extends ISync> implements IEntityService<T> {
|
||||
// Abstract properties - must be implemented by subclasses
|
||||
|
|
@ -36,17 +39,25 @@ export abstract class BaseEntityService<T extends ISync> implements IEntityServi
|
|||
// Internal composition - sync functionality
|
||||
private syncPlugin: SyncPlugin<T>;
|
||||
|
||||
// Protected database instance - accessible to subclasses
|
||||
protected db: IDBDatabase;
|
||||
// IndexedDB context - provides database connection
|
||||
private context: IndexedDBContext;
|
||||
|
||||
/**
|
||||
* @param db - IDBDatabase instance (injected dependency)
|
||||
* @param context - IndexedDBContext instance (injected dependency)
|
||||
*/
|
||||
constructor(db: IDBDatabase) {
|
||||
this.db = db;
|
||||
constructor(context: IndexedDBContext) {
|
||||
this.context = context;
|
||||
this.syncPlugin = new SyncPlugin<T>(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get IDBDatabase instance (lazy access)
|
||||
* Protected getter accessible to subclasses and methods in this class
|
||||
*/
|
||||
protected get db(): IDBDatabase {
|
||||
return this.context.getDatabase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize entity before storing in IndexedDB
|
||||
* Override in subclass if entity has Date fields or needs transformation
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue