mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
use emit
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
048394222b
commit
59280117b0
@ -20,7 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import EventEmitter from "events";
|
import EventEmitter from "events";
|
||||||
import TypedEmitter from "typed-emitter";
|
import type TypedEmitter from "typed-emitter";
|
||||||
import { observable } from "mobx";
|
import { observable } from "mobx";
|
||||||
|
|
||||||
type ExtractEntityMetadataType<Entity> = Entity extends CatalogEntity<infer Metadata> ? Metadata : never;
|
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 {
|
public getId(): string {
|
||||||
return `${this.spec.group}/${this.spec.names.kind}`;
|
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 {
|
export interface CatalogEntityMetadata {
|
||||||
|
|||||||
@ -50,7 +50,7 @@ export class CatalogAddButton extends React.Component<CatalogAddButtonProps> {
|
|||||||
menuItems: this.menuItems
|
menuItems: this.menuItems
|
||||||
};
|
};
|
||||||
|
|
||||||
category.onCatalogAddMenu(context);
|
category.emit("onCatalogAddMenu", context);
|
||||||
}
|
}
|
||||||
}, { fireImmediately: true })
|
}, { fireImmediately: true })
|
||||||
]);
|
]);
|
||||||
|
|||||||
@ -98,19 +98,19 @@ export class CatalogEntityStore extends ItemStore<CatalogEntityItem> {
|
|||||||
|
|
||||||
watch() {
|
watch() {
|
||||||
const disposers: IReactionDisposer[] = [
|
const disposers: IReactionDisposer[] = [
|
||||||
reaction(() => this.entities, async () => await this.loadAll()),
|
reaction(() => this.entities, () => this.loadAll()),
|
||||||
reaction(() => this.activeCategory, () => this.loadAll(), { delay: 100})
|
reaction(() => this.activeCategory, () => this.loadAll(), { delay: 100})
|
||||||
];
|
];
|
||||||
|
|
||||||
return () => disposers.forEach((dispose) => dispose());
|
return () => disposers.forEach((dispose) => dispose());
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadAll() {
|
loadAll() {
|
||||||
if (this.activeCategory) {
|
if (this.activeCategory) {
|
||||||
await this.activeCategory.onLoad();
|
this.activeCategory.emit("onLoad");
|
||||||
} else {
|
} else {
|
||||||
for (const category of catalogCategoryRegistry.items) {
|
for (const category of catalogCategoryRegistry.items) {
|
||||||
await category.onLoad();
|
category.emit("onLoad");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user