mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] add support for top level comments
This commit is contained in:
committed by
Aaron Bohy
parent
779003e715
commit
8a1ac13975
@@ -4,7 +4,7 @@ export { toggler } from "./toggler";
|
||||
export { createBlock } from "./block_compiler";
|
||||
export { list } from "./list";
|
||||
export { multi } from "./multi";
|
||||
export { text } from "./text";
|
||||
export { text, comment } from "./text";
|
||||
export { html } from "./html";
|
||||
|
||||
export interface VNode<T = any> {
|
||||
|
||||
+29
-12
@@ -8,18 +8,17 @@ const nodeInsertBefore = nodeProto.insertBefore;
|
||||
const characterDataSetData = getDescriptor(characterDataProto, "data").set!;
|
||||
const nodeRemoveChild = nodeProto.removeChild;
|
||||
|
||||
class VText {
|
||||
abstract class VSimpleNode {
|
||||
text: string;
|
||||
parentEl?: HTMLElement | undefined;
|
||||
el?: Text;
|
||||
el?: any;
|
||||
|
||||
constructor(text: string) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
mount(parent: HTMLElement, afterNode: Node | null) {
|
||||
mountNode(node: Node, parent: HTMLElement, afterNode: Node | null) {
|
||||
this.parentEl = parent;
|
||||
const node = document.createTextNode(toText(this.text));
|
||||
nodeInsertBefore.call(parent, node, afterNode);
|
||||
this.el = node;
|
||||
}
|
||||
@@ -29,14 +28,6 @@ class VText {
|
||||
nodeInsertBefore.call(this.parentEl, this.el!, target);
|
||||
}
|
||||
|
||||
patch(other: VText) {
|
||||
const text2 = other.text;
|
||||
if (this.text !== text2) {
|
||||
characterDataSetData.call(this.el!, toText(text2));
|
||||
this.text = text2;
|
||||
}
|
||||
}
|
||||
|
||||
beforeRemove() {}
|
||||
|
||||
remove() {
|
||||
@@ -52,10 +43,36 @@ class VText {
|
||||
}
|
||||
}
|
||||
|
||||
class VText extends VSimpleNode {
|
||||
mount(parent: HTMLElement, afterNode: Node | null) {
|
||||
this.mountNode(document.createTextNode(toText(this.text)), parent, afterNode);
|
||||
}
|
||||
|
||||
patch(other: VText) {
|
||||
const text2 = other.text;
|
||||
if (this.text !== text2) {
|
||||
characterDataSetData.call(this.el!, toText(text2));
|
||||
this.text = text2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class VComment extends VSimpleNode {
|
||||
mount(parent: HTMLElement, afterNode: Node | null) {
|
||||
this.mountNode(document.createComment(toText(this.text)), parent, afterNode);
|
||||
}
|
||||
|
||||
patch() {}
|
||||
}
|
||||
|
||||
export function text(str: string): VNode<VText> {
|
||||
return new VText(str);
|
||||
}
|
||||
|
||||
export function comment(str: string): VNode<VComment> {
|
||||
return new VComment(str);
|
||||
}
|
||||
|
||||
export function toText(value: any): string {
|
||||
switch (typeof value) {
|
||||
case "string":
|
||||
|
||||
Reference in New Issue
Block a user