mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
22a79cdedd
in order to separate compiler/ and runtime/ code
66 lines
1.4 KiB
TypeScript
66 lines
1.4 KiB
TypeScript
import type { VNode } from "./index";
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// Toggler node
|
|
// -----------------------------------------------------------------------------
|
|
|
|
class VToggler {
|
|
key: string;
|
|
child: VNode;
|
|
|
|
parentEl?: HTMLElement | undefined;
|
|
|
|
constructor(key: string, child: VNode) {
|
|
this.key = key;
|
|
this.child = child;
|
|
}
|
|
|
|
mount(parent: HTMLElement, afterNode: Node | null) {
|
|
this.parentEl = parent;
|
|
this.child.mount(parent, afterNode);
|
|
}
|
|
|
|
moveBefore(other: VToggler | null, afterNode: Node | null) {
|
|
this.child.moveBefore(other ? other.child : null, afterNode);
|
|
}
|
|
|
|
patch(other: VToggler, withBeforeRemove: boolean) {
|
|
if (this === other) {
|
|
return;
|
|
}
|
|
let child1 = this.child;
|
|
let child2 = other.child;
|
|
if (this.key === other.key) {
|
|
child1.patch(child2, withBeforeRemove);
|
|
} else {
|
|
child2.mount(this.parentEl!, child1.firstNode()!);
|
|
if (withBeforeRemove) {
|
|
child1.beforeRemove();
|
|
}
|
|
child1.remove();
|
|
this.child = child2;
|
|
this.key = other.key;
|
|
}
|
|
}
|
|
|
|
beforeRemove() {
|
|
this.child.beforeRemove();
|
|
}
|
|
|
|
remove() {
|
|
this.child.remove();
|
|
}
|
|
|
|
firstNode(): Node | undefined {
|
|
return this.child.firstNode();
|
|
}
|
|
|
|
toString(): string {
|
|
return this.child.toString();
|
|
}
|
|
}
|
|
|
|
export function toggler(key: string, child: VNode): VNode<VToggler> {
|
|
return new VToggler(key, child);
|
|
}
|