diff --git a/src/common/catalog/catalog-run-event.ts b/src/common/catalog/catalog-run-event.ts index 6861e1e1dc..68a1a4bd08 100644 --- a/src/common/catalog/catalog-run-event.ts +++ b/src/common/catalog/catalog-run-event.ts @@ -22,11 +22,11 @@ import type { CatalogEntity } from "../catalog"; export class CatalogRunEvent { - private _preventDefaulted: boolean; + private _defaultPrevented: boolean; private _target: CatalogEntity; - get preventDefaulted() { - return this._preventDefaulted; + get defaultPrevented() { + return this._defaultPrevented; } get target() { @@ -34,11 +34,11 @@ export class CatalogRunEvent { } constructor({ target }: { target: CatalogEntity }) { - this._preventDefaulted = false; + this._defaultPrevented = false; this._target = target; } preventDefault() { - this._preventDefaulted = true; + this._defaultPrevented = true; } } diff --git a/src/renderer/api/catalog-entity-registry.ts b/src/renderer/api/catalog-entity-registry.ts index 536ab1bf33..58a14018de 100644 --- a/src/renderer/api/catalog-entity-registry.ts +++ b/src/renderer/api/catalog-entity-registry.ts @@ -32,7 +32,7 @@ import { catalogEntityRunContext } from "./catalog-entity"; import { CatalogRunEvent } from "../../common/catalog/catalog-run-event"; export type EntityFilter = (entity: CatalogEntity) => any; -export type CatalogEntityOnBeforeRun = ((event: CatalogRunEvent) => void) | ((event: CatalogRunEvent) => Promise); +export type CatalogEntityOnBeforeRun = (event: CatalogRunEvent) => void | Promise; export class CatalogEntityRegistry { @observable protected activeEntityId: string | undefined = undefined; @@ -198,25 +198,19 @@ export class CatalogEntityRegistry { async onBeforeRun(entity: CatalogEntity): Promise { logger.debug(`[CATALOG-ENTITY-REGISTRY]: run onBeforeRun on ${entity.getId()}`); + const runEvent = new CatalogRunEvent({ target: entity }); + for (const onBeforeRun of this.onBeforeRunHooks) { - try { - const runEvent = new CatalogRunEvent({ target: entity }); - + try {  await onBeforeRun(runEvent); - - const shouldContinue = !runEvent.preventDefaulted; - - return shouldContinue; } catch (error) { logger.warn(`[CATALOG-ENTITY-REGISTRY]: entity ${entity.getId()} onBeforeRun threw an error`, error); - - // If a handler throws treat it as if it has returned `false` - // Namely: assume that its internal logic has failed and didn't complete as expected - return false; } } - return true; + const shouldContinue = !runEvent.defaultPrevented; + + return shouldContinue; } /**