Rewrote all plugs using MarkdownTree

This commit is contained in:
Zef Hemel
2022-04-04 11:51:41 +02:00
parent 07453d638b
commit 16577c8ea2
17 changed files with 332 additions and 255 deletions
+4 -6
View File
@@ -1,6 +1,6 @@
import { Hook, Manifest } from "../types";
import { System } from "../system";
import { safeRun } from "../util";
import {Hook, Manifest} from "../types";
import {System} from "../system";
import {safeRun} from "../util";
// System events:
// - plug:load (plugName: string)
@@ -16,7 +16,6 @@ export class EventHook implements Hook<EventHookT> {
if (!this.system) {
throw new Error("Event hook is not initialized");
}
let promises: Promise<void>[] = [];
for (const plug of this.system.loadedPlugs.values()) {
for (const [name, functionDef] of Object.entries(
plug.manifest!.functions
@@ -24,12 +23,11 @@ export class EventHook implements Hook<EventHookT> {
if (functionDef.events && functionDef.events.includes(eventName)) {
// Only dispatch functions that can run in this environment
if (plug.canInvoke(name)) {
promises.push(plug.invoke(name, [data]));
await plug.invoke(name, [data]);
}
}
}
}
await Promise.all(promises);
}
apply(system: System<EventHookT>): void {
+1 -1
View File
@@ -3,7 +3,7 @@ import {EventHook} from "../hooks/event";
export function eventSyscalls(eventHook: EventHook): SysCallMapping {
return {
"event.dispatch": async(ctx, eventName: string, data: any) => {
"event.dispatch": async (ctx, eventName: string, data: any) => {
return eventHook.dispatchEvent(eventName, data);
},
};
+1 -1
View File
@@ -7,7 +7,7 @@ export function fetchSyscalls(): SysCallMapping {
let resp = await fetch(url, init);
return resp.json();
},
"fetch.text": async(ctx, url: RequestInfo, init: RequestInit) => {
"fetch.text": async (ctx, url: RequestInfo, init: RequestInit) => {
let resp = await fetch(url, init);
return resp.text();
},