1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2021-05-21 14:23:55 +03:00
parent 048394222b
commit 59280117b0
3 changed files with 6 additions and 18 deletions

View File

@ -20,7 +20,7 @@
*/
import EventEmitter from "events";
import TypedEmitter from "typed-emitter";
import type TypedEmitter from "typed-emitter";
import { observable } from "mobx";
type ExtractEntityMetadataType<Entity> = Entity extends CatalogEntity<infer Metadata> ? Metadata : never;
@ -66,18 +66,6 @@ export abstract class CatalogCategory extends (EventEmitter as new () => TypedEm
public getId(): string {
return `${this.spec.group}/${this.spec.names.kind}`;
}
public async onLoad(): Promise<void> {
for( const listener of this.listeners("onLoad")) {
await listener();
}
}
public async onCatalogAddMenu(context: CatalogEntityAddMenuContext): Promise<void> {
for( const listener of this.listeners("onCatalogAddMenu")) {
await listener(context);
}
}
}
export interface CatalogEntityMetadata {

View File

@ -50,7 +50,7 @@ export class CatalogAddButton extends React.Component<CatalogAddButtonProps> {
menuItems: this.menuItems
};
category.onCatalogAddMenu(context);
category.emit("onCatalogAddMenu", context);
}
}, { fireImmediately: true })
]);

View File

@ -98,19 +98,19 @@ export class CatalogEntityStore extends ItemStore<CatalogEntityItem> {
watch() {
const disposers: IReactionDisposer[] = [
reaction(() => this.entities, async () => await this.loadAll()),
reaction(() => this.entities, () => this.loadAll()),
reaction(() => this.activeCategory, () => this.loadAll(), { delay: 100})
];
return () => disposers.forEach((dispose) => dispose());
}
async loadAll() {
loadAll() {
if (this.activeCategory) {
await this.activeCategory.onLoad();
this.activeCategory.emit("onLoad");
} else {
for (const category of catalogCategoryRegistry.items) {
await category.onLoad();
category.emit("onLoad");
}
}