1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Make startCatalogEntitySync a dependency of CatalogEntityRegistry

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-02-11 10:02:30 -05:00
parent 38211c8b1e
commit 47ddec78cd

View File

@ -17,7 +17,7 @@ import { catalogEntityRunListener } from "../../common/ipc/catalog";
import { navigate } from "../navigation";
import { isMainFrame } from "process";
import { startCatalogEntitySync } from "./catalog-entity-sync";
import type { RawCatalogEntity, RawCatalogEntityUpdate } from "../../common/catalog/entity-sync";
import type { EntityChangeEvents, RawCatalogEntity, RawCatalogEntityUpdate } from "../../common/catalog/entity-sync";
export type EntityFilter = (entity: CatalogEntity) => any;
export type CatalogEntityOnBeforeRun = (event: CatalogRunEvent) => void | Promise<void>;
@ -29,6 +29,11 @@ export const catalogEntityRunContext = {
},
};
export interface CatalogEntityRegistryDependencies {
categoryRegistry: CatalogCategoryRegistry;
initSync: (handlers: EntityChangeEvents) => void;
}
export class CatalogEntityRegistry {
@observable protected activeEntityId: string | undefined = undefined;
protected _entities = observable.map<string, CatalogEntity>([], { deep: true });
@ -44,7 +49,7 @@ export class CatalogEntityRegistry {
*/
protected rawEntities = new Map<string, CatalogEntityData & CatalogEntityKindData>();
constructor(private categoryRegistry: CatalogCategoryRegistry) {
constructor(protected readonly dependencies: CatalogEntityRegistryDependencies) {
makeObservable(this);
}
@ -80,7 +85,7 @@ export class CatalogEntityRegistry {
}
init() {
startCatalogEntitySync({
this.dependencies.initSync({
delete: this.onDeleteEvent,
add: this.onAddEvent,
update: this.onUpdateEvent,
@ -126,7 +131,7 @@ export class CatalogEntityRegistry {
@action
protected addItem(item: (CatalogEntityData & CatalogEntityKindData)) {
const entity = this.categoryRegistry.getEntityForData(item);
const entity = this.dependencies.categoryRegistry.getEntityForData(item);
if (entity) {
this._entities.set(entity.getId(), entity);
@ -256,7 +261,10 @@ export class CatalogEntityRegistry {
}
}
export const catalogEntityRegistry = new CatalogEntityRegistry(catalogCategoryRegistry);
export const catalogEntityRegistry = new CatalogEntityRegistry({
categoryRegistry: catalogCategoryRegistry,
initSync: startCatalogEntitySync,
});
export function getActiveClusterEntity(): Cluster | undefined {
return ClusterStore.getInstance().getById(catalogEntityRegistry.activeEntity?.getId());