Skip to content

Commit

Permalink
Added dom id
Browse files Browse the repository at this point in the history
  • Loading branch information
Arpita-Jaiswal committed Oct 6, 2023
1 parent 6ffd098 commit 4618225
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
14 changes: 10 additions & 4 deletions fastn-js/js/virtual.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@ class ClassList {
}

class Node {
#id
id
#dataId
#tagName
#children
#attributes
constructor(id, tagName) {
this.#tagName = tagName;
this.#id = id;
this.#dataId = id;
this.classList = new ClassList();
this.#children = [];
this.#attributes = {};
this.innerHTML = "";
this.style = {};
this.onclick = null;
this.id = null;
}
appendChild(c) {
this.#children.push(c);
Expand Down Expand Up @@ -66,7 +68,7 @@ class Node {
}
// Caution: This is only supported in ssr mode
toHtmlAsString() {
const openingTag = `<${this.#tagName}${this.getDataIdString()}${this.getAttributesString()}${this.getClassString()}${this.getStyleString()}>`;
const openingTag = `<${this.#tagName}${this.getDataIdString()}${this.getIdString()}${this.getAttributesString()}${this.getClassString()}${this.getStyleString()}>`;
const closingTag = `</${this.#tagName}>`;
const innerHTML = this.innerHTML;
const childNodes = this.#children.map(child => child.toHtmlAsString()).join('');
Expand All @@ -75,7 +77,11 @@ class Node {
}
// Caution: This is only supported in ssr mode
getDataIdString() {
return ` data-id="${this.#id}"`;
return ` data-id="${this.#dataId}"`;
}
// Caution: This is only supported in ssr mode
getIdString() {
return fastn_utils.isNull(this.id) ? "": ` id="${this.id}"`;
}
// Caution: This is only supported in ssr mode
getClassString() {
Expand Down
1 change: 1 addition & 0 deletions ftd/t/js/01-basic.ftd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
export: print

-- ftd.text: "Hello"
id: hello-id

-- ftd.text: Hello
background.solid: $inherited.colors.background.step-1
Expand Down
3 changes: 2 additions & 1 deletion ftd/t/js/01-basic.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ftd/t/js/03-common-properties.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ftd/t/js/18-rive.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4618225

Please sign in to comment.