[IMP] component: validate mounting target at patch time

This commit is contained in:
Géry Debongnie
2022-01-31 16:57:58 +01:00
committed by Aaron Bohy
parent bd98d4d0d0
commit 50aac42bdc
5 changed files with 47 additions and 10 deletions
+9
View File
@@ -24,6 +24,15 @@ export function batched(callback: Callback): Callback {
};
}
export function validateTarget(target: HTMLElement) {
if (!(target instanceof HTMLElement)) {
throw new Error("Cannot mount component: the target is not a valid DOM element");
}
if (!document.body.contains(target)) {
throw new Error("Cannot mount a component on a detached dom node");
}
}
export class EventBus extends EventTarget {
trigger(name: string, payload?: any) {
this.dispatchEvent(new CustomEvent(name, { detail: payload }));