Use distance filter

This commit is contained in:
Zef Hemel
2022-03-29 12:13:46 +02:00
parent b89aee97d7
commit c6628927ba
15 changed files with 136 additions and 65 deletions
+1 -2
View File
@@ -44,8 +44,7 @@ return fn["default"].apply(null, arguments);`;
self.addEventListener("message", (event: { data: WorkerMessage }) => {
safeRun(async () => {
let messageEvent = event;
let data = messageEvent.data;
let data = event.data;
switch (data.type) {
case "load":
loadedFunctions.set(data.name!, new Function(wrapScript(data.code!)));
+1 -1
View File
@@ -27,7 +27,7 @@ export type EndPointDef = {
export class EndpointHook implements Hook<EndpointHookT> {
private app: Express;
private prefix: string;
readonly prefix: string;
constructor(app: Express, prefix: string) {
this.app = app;
+7 -4
View File
@@ -1,5 +1,6 @@
import { Hook, Manifest } from "../types";
import { System } from "../system";
import { safeRun } from "../util";
// System events:
// - plug:load (plugName: string)
@@ -11,11 +12,11 @@ export type EventHookT = {
export class EventHook implements Hook<EventHookT> {
private system?: System<EventHookT>;
async dispatchEvent(eventName: string, data?: any): Promise<any[]> {
async dispatchEvent(eventName: string, data?: any): Promise<void> {
if (!this.system) {
throw new Error("Event hook is not initialized");
}
let promises: Promise<any>[] = [];
let promises: Promise<void>[] = [];
for (const plug of this.system.loadedPlugs.values()) {
for (const [name, functionDef] of Object.entries(
plug.manifest!.functions
@@ -28,14 +29,16 @@ export class EventHook implements Hook<EventHookT> {
}
}
}
return Promise.all(promises);
await Promise.all(promises);
}
apply(system: System<EventHookT>): void {
this.system = system;
this.system.on({
plugLoaded: (name) => {
this.dispatchEvent("plug:load", name);
safeRun(async () => {
await this.dispatchEvent("plug:load", name);
});
},
});
}