[REF] allow external code to override validateTarget

This commit is contained in:
Géry Debongnie
2022-02-01 16:08:01 +01:00
committed by Aaron Bohy
parent 50aac42bdc
commit 83de53d283
3 changed files with 5 additions and 4 deletions
+3 -1
View File
@@ -28,6 +28,8 @@ export class App<
P = any,
E = any
> extends TemplateSet {
static validateTarget = validateTarget;
Root: ComponentConstructor<P, E>;
props: P;
env: E;
@@ -49,7 +51,7 @@ export class App<
}
mount(target: HTMLElement, options?: MountOptions): Promise<Component<P, E> & InstanceType<T>> {
validateTarget(target);
App.validateTarget(target);
const node = this.makeNode(this.Root, this.props);
const prom = this.mountNode(node, target, options);
this.root = node;
+1 -2
View File
@@ -1,5 +1,4 @@
import { BDom, mount } from "../blockdom";
import { validateTarget } from "../utils";
import type { ComponentNode } from "./component_node";
import { fibersInError, handleError } from "./error_handling";
import { STATUS } from "./status";
@@ -159,8 +158,8 @@ export class MountFiber extends RootFiber {
complete() {
let current: Fiber | undefined = this;
try {
validateTarget(this.target);
const node = this.node;
(node.app.constructor as any).validateTarget(this.target);
if (node.bdom) {
// this is a complicated situation: if we mount a fiber with an existing
// bdom, this means that this same fiber was already completed, mounted,
@@ -81,7 +81,7 @@ exports[`basics a class component inside a class component, no external dom 2`]
}"
`;
exports[`basics a component cannot be mounted in a detached node (even if node is detached later 1`] = `
exports[`basics a component cannot be mounted in a detached node (even if node is detached later) 1`] = `
"function anonymous(bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;