diff --git a/src/renderer/api/catalog-entity-registry.ts b/src/renderer/api/catalog-entity-registry.ts index 876ad40ddc..5d3e52f823 100644 --- a/src/renderer/api/catalog-entity-registry.ts +++ b/src/renderer/api/catalog-entity-registry.ts @@ -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; @@ -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([], { deep: true }); @@ -44,7 +49,7 @@ export class CatalogEntityRegistry { */ protected rawEntities = new Map(); - 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());