use document fragment

This commit is contained in:
Mylloon 2024-12-12 16:25:43 +01:00
parent 47e386222f
commit 52e3674140
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -5,7 +5,10 @@
* @param {string} location Current location, used for links creation
*/
const buildFileTree = (parent, data, location) => {
const fragment = document.createDocumentFragment();
const ul = document.createElement("ul");
fragment.appendChild(ul);
data.forEach((item) => {
const li = document.createElement("li");
li.classList.add(item.is_dir ? "directory" : "file");
@ -32,16 +35,16 @@ const buildFileTree = (parent, data, location) => {
ul.appendChild(li);
if (item.children && item.children.length > 0) {
if (item.children?.length) {
buildFileTree(
li,
item.children,
item.is_dir ? location + `${item.name}/` : location
item.is_dir ? `${location}${item.name}/` : location
);
}
});
parent.appendChild(ul);
parent.appendChild(fragment);
};
/**