Add onRunHook extension api

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
This commit is contained in:
Hung-Han (Henry) Chen committed 2021-10-04 16:04:37 +03:00
1 parent 0f63ccbb82
commit cfdb4c93c1
8 files changed
+289 -7

No files matched your search

+28 -1
View File
@@ -22,7 +22,7 @@
import type { CatalogCategory, CatalogEntity } from "../../common/catalog";
import { catalogEntityRegistry as registry } from "../../renderer/api/catalog-entity-registry";
import type { CatelogEntityOnRunHook } from "../../renderer/api/catalog-entity-registry";
export { catalogCategoryRegistry as catalogCategories } from "../../common/catalog/catalog-category-registry";
export class CatalogEntityRegistry {
@@ -48,6 +48,33 @@ export class CatalogEntityRegistry {
getItemsForCategory<T extends CatalogEntity>(category: CatalogCategory): T[] {
return registry.getItemsForCategory(category);
}
/**
* Add a onRun hook to a catalog entity.
* @param catalogEntityUid The uid of the catalog entity
* @param onRunHook The function that should return a boolean if the onRun of catalog entity should be triggered.
* @returns A function to remove that hook
*/
addOnRunHook(catalogEntityUid: CatalogEntity["metadata"]["uid"], onRunHook: CatelogEntityOnRunHook) {
return registry.addOnRunHook(catalogEntityUid, onRunHook);
}
/**
* Returns one catalog entity onRun hook by catalog entity uid
*/
getOnRunHook(catalogEntityUid: CatalogEntity["metadata"]["uid"]): CatelogEntityOnRunHook | undefined {
return registry.getOnRunHook(catalogEntityUid);
}
/**
* Returns all catalog entities' onRun hooks
*/
getAllOnRunHooks(): Array<{
catalogEntityUid: CatalogEntity["metadata"]["uid"];
onRunHook: CatelogEntityOnRunHook;
}> {
return registry.getAllOnRunHooks();
}
}
export const catalogEntities = new CatalogEntityRegistry();