Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen committed 2021-05-21 14:23:55 +03:00
1 parent 048394222b
commit 59280117b0
3 files changed
+6 -18

No files matched your search

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