Adjust SuiWeb according to the standards
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Manuel Thalmann 2022-12-15 21:53:30 +01:00
parent dedf7886e5
commit 8f488f48bd

View file

@ -11,6 +11,9 @@ export class SuiWeb
* *
* @param {HTMLElement} element * @param {HTMLElement} element
* The element to add the rendered node to. * The element to add the rendered node to.
*
* @returns {Node}
* The resulting element.
*/ */
static render(data, element) static render(data, element)
{ {
@ -19,14 +22,33 @@ export class SuiWeb
let descriptor = data[0]; let descriptor = data[0];
let args = data.slice(1); let args = data.slice(1);
if (typeof descriptor === "function") if (typeof descriptor === "function" || typeof descriptor === "string")
{ {
SuiWeb.render(descriptor(...args), element); /**
} * @type {HTMLElement}
else if (typeof descriptor === "string") */
{ let result;
let result = element.ownerDocument.createElement(descriptor);
element.appendChild(result); if (typeof descriptor === "function")
{
/**
* @type {any[]}
*/
let arg = [];
if (typeof args[0] === "object" && !Array.isArray(args[0]))
{
arg = [args[0]];
args = args.slice(1);
}
result = /** @type {HTMLElement} */ (SuiWeb.render(descriptor(...arg), element));
}
else
{
result = element.ownerDocument.createElement(descriptor);
element.appendChild(result);
}
for (let arg of args) for (let arg of args)
{ {
@ -39,6 +61,8 @@ export class SuiWeb
SuiWeb.render(arg, result); SuiWeb.render(arg, result);
} }
} }
return result;
} }
else else
{ {
@ -47,7 +71,7 @@ export class SuiWeb
} }
else if (typeof data === "string") else if (typeof data === "string")
{ {
element.appendChild(element.ownerDocument.createTextNode(data)); return element.appendChild(element.ownerDocument.createTextNode(data));
} }
else else
{ {