mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Before hook for onRun of Catalog entities (#3911)
Co-authored-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
851274d314
commit
4af796c532
17 files changed
+636
-128
No files matched your search
@@ -77,7 +77,7 @@ export class LensRendererExtension extends LensExtension {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a filtering function for the catalog catogries. This will be removed if the extension is disabled.
|
||||
* Add a filtering function for the catalog categories. This will be removed if the extension is disabled.
|
||||
* @param fn The function which should return a truthy value for those categories which should be kept.
|
||||
* @returns A function to clean up the filter
|
||||
*/
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
|
||||
import type { CatalogCategory, CatalogEntity } from "../../common/catalog";
|
||||
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";
|
||||
export { catalogCategoryRegistry as catalogCategories } from "../../common/catalog/catalog-category-registry";
|
||||
|
||||
export class CatalogEntityRegistry {
|
||||
@@ -48,6 +49,16 @@ export class CatalogEntityRegistry {
|
||||
getItemsForCategory<T extends CatalogEntity>(category: CatalogCategory): T[] {
|
||||
return registry.getItemsForCategory(category);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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);
|
||||
}
|
||||
}
|
||||
|
||||
export const catalogEntities = new CatalogEntityRegistry();
|
||||
Reference in new issue
Block a user