diff --git a/src/lib/services/entities-map.service.ts b/src/lib/services/entities-map.service.ts index 44ee10c..d7d7302 100644 --- a/src/lib/services/entities-map.service.ts +++ b/src/lib/services/entities-map.service.ts @@ -10,7 +10,8 @@ export abstract class EntitiesMapService, I> { private readonly _entityChanged$ = new Subject(); private readonly _entityDeleted$ = new Subject(); - protected constructor(@Inject('ENTITY_PRIMARY_KEY') protected readonly _primaryKey: string) {} + protected constructor(@Inject('ENTITY_PRIMARY_KEY') protected readonly _primaryKey: string) { + } get empty(): boolean { return this._map.size === 0; @@ -73,6 +74,7 @@ export abstract class EntitiesMapService, I> { } replace(entities: E[]) { + /** Return true if files were replaced or false if not **/ const key = this._pluckPrimaryKey(entities[0]); const entityIds = entities.map(entity => entity.id); const existingEntities = this.get(key).filter(entity => entityIds.includes(entity.id)); @@ -80,10 +82,14 @@ export abstract class EntitiesMapService, I> { const old = existingEntities.find(e => e.id === entity.id); return !old || !entity.isEqual(old); }); + if (newEntities.length) { const all = this.get(key).filter(e => !newEntities.map(entity => entity.id).includes(e.id)); this.set(key, [...all, ...newEntities]); + return true; } + + return false; } @Validate()