Skip to content

Commit

Permalink
Add dom node after created
Browse files Browse the repository at this point in the history
  • Loading branch information
Arpita-Jaiswal committed Jul 12, 2024
1 parent b0eed70 commit 8bd579c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions fastn-js/js/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -1929,10 +1929,25 @@ class Node2 {
);
this.#mutables.push(ftd.dark_mode);
}
createClonedNode() {
if (!doubleBuffering) {
let node = this.#node;
let clonedNode = node.cloneNode(true);
this.#node = clonedNode;
return node;
}
}

replaceNodeWithClonedNode(node) {
if (!doubleBuffering) {
node.parentNode.replaceChild(this.#node, node);
}
}
setStaticProperty(kind, value, inherited) {
// value can be either static or mutable
let staticValue = fastn_utils.getStaticValue(value);
if (kind === fastn_dom.PropertyKind.Children) {
let originalNode = this.createClonedNode();
if (fastn_utils.isWrapperNode(this.#tagName)) {
let parentWithSibiling = this.#parent;
if (Array.isArray(staticValue)) {
Expand Down Expand Up @@ -1969,6 +1984,7 @@ class Node2 {
this.#children.push(staticValue(this, inherited));
}
}
this.replaceNodeWithClonedNode(originalNode);
} else if (kind === fastn_dom.PropertyKind.Id) {
this.#node.id = staticValue;
} else if (kind === fastn_dom.PropertyKind.BreakpointWidth) {
Expand Down

0 comments on commit 8bd579c

Please sign in to comment.