Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dom node after created #1928

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading