1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/common/catalog/catalog-entity-registry.ts
Sebastian Malton 7538560175 Switch CatalogEntity and CatalogCategory abstract classes
Signed-off-by: Sebastian Malton <sebastian@malton.name>
2021-04-23 11:10:25 -04:00

27 lines
832 B
TypeScript

import { action, computed, observable, IObservableArray } from "mobx";
import { CatalogEntity } from "./catalog-entity";
export class CatalogEntityRegistry {
protected sources = observable.map<string, IObservableArray<CatalogEntity>>([], { deep: true });
@action addSource(id: string, source: IObservableArray<CatalogEntity>) {
this.sources.set(id, source);
}
@action removeSource(id: string) {
this.sources.delete(id);
}
@computed get items(): CatalogEntity[] {
return Array.from(this.sources.values()).flat();
}
getItemsForApiKind<T extends CatalogEntity>(apiVersion: string, kind: string): T[] {
const items = this.items.filter((item) => item.apiVersion === apiVersion && item.kind === kind);
return items as T[];
}
}
export const catalogEntityRegistry = new CatalogEntityRegistry();