Template cleanup, autocomplete for more query stuff

This commit is contained in:
Zef Hemel
2022-07-04 15:07:27 +02:00
parent e2e7e2f936
commit 60cfefbc95
18 changed files with 235 additions and 69 deletions
+24
View File
@@ -21,6 +21,30 @@ export class EventHook implements Hook<EventHookT> {
this.localListeners.get(eventName)!.push(callback);
}
// Pull all events listened to
listEvents(): string[] {
if (!this.system) {
throw new Error("Event hook is not initialized");
}
let eventNames = new Set<string>();
for (const plug of this.system.loadedPlugs.values()) {
for (const [name, functionDef] of Object.entries(
plug.manifest!.functions
)) {
if (functionDef.events) {
for (let eventName of functionDef.events) {
eventNames.add(eventName);
}
}
}
}
for (let eventName of this.localListeners.keys()) {
eventNames.add(eventName);
}
return [...eventNames];
}
async dispatchEvent(eventName: string, data?: any): Promise<any[]> {
if (!this.system) {
throw new Error("Event hook is not initialized");
+3
View File
@@ -6,5 +6,8 @@ export function eventSyscalls(eventHook: EventHook): SysCallMapping {
"event.dispatch": async (ctx, eventName: string, data: any) => {
return eventHook.dispatchEvent(eventName, data);
},
"event.list": async () => {
return eventHook.listEvents();
},
};
}