From 82ad163af0dbb8d89c70986148c9ce8d960d071f Mon Sep 17 00:00:00 2001 From: "Hung-Han (Henry) Chen" Date: Thu, 7 Oct 2021 10:39:49 +0300 Subject: [PATCH] Allow entity uid Signed-off-by: Hung-Han (Henry) Chen --- src/extensions/renderer-api/catalog.ts | 7 ++++--- src/renderer/api/catalog-entity-registry.ts | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/extensions/renderer-api/catalog.ts b/src/extensions/renderer-api/catalog.ts index 389107c80d..fb91c3033a 100644 --- a/src/extensions/renderer-api/catalog.ts +++ b/src/extensions/renderer-api/catalog.ts @@ -21,6 +21,7 @@ import type { CatalogCategory, CatalogEntity } from "../../common/catalog"; +import type { CatalogEntityUid } from "../../renderer/api/catalog-entity-registry"; import { catalogEntityRegistry as registry } from "../../renderer/api/catalog-entity-registry"; import type { CatalogEntityOnBeforeRun } from "../../renderer/api/catalog-entity-registry"; import type { Disposer } from "../../common/utils"; @@ -52,12 +53,12 @@ export class CatalogEntityRegistry { /** * Add a onBeforeRun hook to a catalog entity. If `onBeforeRun` was previously added then it will not be added again - * @param catalogEntityUid The uid of the catalog entity + * @param entityOrId Catalog entity or the uid of the catalog entity * @param onBeforeRun The function that should return a boolean if the onRun of catalog entity should be triggered. * @returns A function to remove that hook */ - addOnBeforeRun(entity: CatalogEntity, onBeforeRun: CatalogEntityOnBeforeRun): Disposer { - return registry.addOnBeforeRun(entity, onBeforeRun); + addOnBeforeRun(entityOrId: CatalogEntity | CatalogEntityUid, onBeforeRun: CatalogEntityOnBeforeRun): Disposer { + return registry.addOnBeforeRun(entityOrId, onBeforeRun); } } diff --git a/src/renderer/api/catalog-entity-registry.ts b/src/renderer/api/catalog-entity-registry.ts index f9c59fce09..6b8b31d0e1 100644 --- a/src/renderer/api/catalog-entity-registry.ts +++ b/src/renderer/api/catalog-entity-registry.ts @@ -33,7 +33,7 @@ import { catalogEntityRunContext } from "./catalog-entity"; export type EntityFilter = (entity: CatalogEntity) => any; export type CatalogEntityOnBeforeRun = (entity: CatalogEntity) => boolean | Promise; -type CatalogEntityUid = CatalogEntity["metadata"]["uid"]; +export type CatalogEntityUid = CatalogEntity["metadata"]["uid"]; export class CatalogEntityRegistry { @observable protected activeEntityId: string | undefined = undefined; @@ -180,7 +180,7 @@ export class CatalogEntityRegistry { /** * Add a onBeforeRun hook to a catalog entity. If `onBeforeRun` was previously added then it will not be added again - * @param catalogEntityUid The uid of the catalog entity + * @param entityOrId Catalog entity or the uid of the catalog entity * @param onBeforeRun The function that should return a boolean if the onRun of catalog entity should be triggered. * @returns A function to remove that hook */