mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
24 lines
658 B
TypeScript
24 lines
658 B
TypeScript
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();
|
|
}
|