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

Fix onBeforeRun iteration logic

Signed-off-by: Juho Heikka <juho.heikka@gmail.com>
This commit is contained in:
Juho Heikka 2021-10-07 18:58:57 +03:00
parent 912f239abb
commit 3e500abf3f
3 changed files with 16 additions and 16 deletions

View File

@ -22,23 +22,23 @@
import type { CatalogEntity } from "../catalog";
export class CatalogRunEvent {
private _defaultPrevented: boolean;
private _target: CatalogEntity;
#defaultPrevented: boolean;
#target: CatalogEntity;
get defaultPrevented() {
return this._defaultPrevented;
return this.#defaultPrevented;
}
get target() {
return this._target;
return this.#target;
}
constructor({ target }: { target: CatalogEntity }) {
this._defaultPrevented = false;
this._target = target;
this.#defaultPrevented = false;
this.#target = target;
}
preventDefault() {
this._defaultPrevented = true;
this.#defaultPrevented = true;
}
}

View File

@ -206,11 +206,13 @@ export class CatalogEntityRegistry {
} catch (error) {
logger.warn(`[CATALOG-ENTITY-REGISTRY]: entity ${entity.getId()} onBeforeRun threw an error`, error);
}
if (runEvent.defaultPrevented) {
return false;
}
}
const shouldContinue = !runEvent.defaultPrevented;
return shouldContinue;
return true;
}
/**

View File

@ -158,8 +158,6 @@ describe("<Catalog />", () => {
expect(onRun).toHaveBeenCalled();
done();
}, 500);
return true;
}
);
@ -213,7 +211,7 @@ describe("<Catalog />", () => {
userEvent.click(screen.getByTestId("detail-panel-hot-bar-icon"));
});
it("addOnBeforeRun throw an exception => onRun wont be triggered", (done) => {
it("addOnBeforeRun throw an exception => onRun will be triggered", (done) => {
const catalogCategoryRegistry = new CatalogCategoryRegistry();
const catalogEntityRegistry = new CatalogEntityRegistry(catalogCategoryRegistry);
const catalogEntityStore = new CatalogEntityStore(catalogEntityRegistry);
@ -232,7 +230,7 @@ describe("<Catalog />", () => {
catalogEntityRegistry.addOnBeforeRun(
() => {
setTimeout(() => {
expect(onRun).not.toHaveBeenCalled();
expect(onRun).toHaveBeenCalled();
done();
}, 500);
@ -327,7 +325,7 @@ describe("<Catalog />", () => {
userEvent.click(screen.getByTestId("detail-panel-hot-bar-icon"));
});
it("addOnRunHook return a promise and reject => onRun wont be triggered", (done) => {
it("addOnRunHook return a promise and reject => onRun will be triggered", (done) => {
const catalogCategoryRegistry = new CatalogCategoryRegistry();
const catalogEntityRegistry = new CatalogEntityRegistry(catalogCategoryRegistry);
const catalogEntityStore = new CatalogEntityStore(catalogEntityRegistry);
@ -346,7 +344,7 @@ describe("<Catalog />", () => {
catalogEntityRegistry.addOnBeforeRun(
async () => {
setTimeout(() => {
expect(onRun).not.toHaveBeenCalled();
expect(onRun).toHaveBeenCalled();
done();
}, 500);