mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
27 lines
832 B
TypeScript
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();
|