remove primarykey property from entities map
This commit is contained in:
parent
b638c5f074
commit
46b630de82
@ -6,10 +6,8 @@ import { List, RequiredParam, shareLast, Validate } from '../utils';
|
||||
import { Id } from '../listing/models/trackable';
|
||||
import { isArray } from '../permissions';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
@Injectable()
|
||||
export abstract class EntitiesMapService<Interface, Class extends Entity<Interface, PrimaryKey>, PrimaryKey extends Id = Class['id']> {
|
||||
protected abstract readonly _primaryKey: string;
|
||||
|
||||
protected readonly _map = new Map<Id, BehaviorSubject<Class[]>>();
|
||||
readonly #entityChanged$ = new Subject<Class>();
|
||||
readonly #entitiesChanged$ = new BehaviorSubject<boolean>(false);
|
||||
@ -48,8 +46,8 @@ export abstract class EntitiesMapService<Interface, Class extends Entity<Interfa
|
||||
}
|
||||
|
||||
get(key: Id): Class[];
|
||||
get(key: Id, id: Id): Class | undefined;
|
||||
get(key: Id, id?: Id): Class | Class[] | undefined {
|
||||
get(key: Id, id: PrimaryKey): Class | undefined;
|
||||
get(key: Id, id?: PrimaryKey): Class | Class[] | undefined {
|
||||
const value = this._getBehaviourSubject(key)?.value;
|
||||
if (!id) {
|
||||
return value ?? [];
|
||||
@ -119,8 +117,7 @@ export abstract class EntitiesMapService<Interface, Class extends Entity<Interfa
|
||||
return false;
|
||||
}
|
||||
|
||||
@Validate()
|
||||
watch$(@RequiredParam() key: Id, @RequiredParam() entityId: Id): Observable<Class> {
|
||||
watch$(key: string, @RequiredParam() entityId: PrimaryKey): Observable<Class> {
|
||||
return this.#entityChanged$.pipe(
|
||||
filter(entity => entity.id === entityId),
|
||||
startWith(this.get(key, entityId) as Class),
|
||||
@ -138,7 +135,7 @@ export abstract class EntitiesMapService<Interface, Class extends Entity<Interfa
|
||||
);
|
||||
}
|
||||
|
||||
watchDeleted$(entityId: Id): Observable<Class> {
|
||||
watchDeleted$(entityId: PrimaryKey): Observable<Class> {
|
||||
return this.#entityDeleted$.pipe(filter(entity => entity.id === entityId));
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user