[REF] move event_bus into utils, readd 2 functions

This commit is contained in:
Géry Debongnie
2021-11-13 16:21:01 +01:00
committed by Aaron Bohy
parent c1439814bf
commit 1658d15b87
7 changed files with 33 additions and 10 deletions
+23
View File
@@ -0,0 +1,23 @@
export class EventBus extends EventTarget {
trigger(name: string, payload?: any) {
this.dispatchEvent(new CustomEvent(name, { detail: payload }));
}
}
export function whenReady(fn?: any): Promise<void> {
return new Promise(function (resolve) {
if (document.readyState !== "loading") {
resolve(true);
} else {
document.addEventListener("DOMContentLoaded", resolve, false);
}
}).then(fn || function () {});
}
export async function loadFile(url: string): Promise<string> {
const result = await fetch(url);
if (!result.ok) {
throw new Error("Error while fetching xml templates");
}
return await result.text();
}