Nest render
function in separate class
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
babdc6104e
commit
5ff474a7ea
|
@ -1,6 +1,6 @@
|
||||||
import { App } from "./Components.js";
|
import { App } from "./Components.js";
|
||||||
import { State } from "./State.js";
|
import { State } from "./State.js";
|
||||||
import { render } from "./SuiWeb.js";
|
import { SuiWeb } from "./SuiWeb.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a game.
|
* Represents a game.
|
||||||
|
@ -171,7 +171,7 @@ export class Game
|
||||||
{
|
{
|
||||||
let container = document.getElementById(this.id);
|
let container = document.getElementById(this.id);
|
||||||
container.innerHTML = "";
|
container.innerHTML = "";
|
||||||
render([App, this], container);
|
SuiWeb.render([App, this], container);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
/**
|
/**
|
||||||
|
* Provides component for rendering elements written in SJDON notation.
|
||||||
|
*/
|
||||||
|
export class SuiWeb
|
||||||
|
{
|
||||||
|
/**
|
||||||
* Renders the specified {@link data `data`} and appends it to the specified {@link element `element`}.
|
* Renders the specified {@link data `data`} and appends it to the specified {@link element `element`}.
|
||||||
*
|
*
|
||||||
* @param {NodeDescriptor} data
|
* @param {NodeDescriptor} data
|
||||||
|
@ -7,8 +12,8 @@
|
||||||
* @param {HTMLElement} element
|
* @param {HTMLElement} element
|
||||||
* The element to add the rendered node to.
|
* The element to add the rendered node to.
|
||||||
*/
|
*/
|
||||||
export function render(data, element)
|
static render(data, element)
|
||||||
{
|
{
|
||||||
if (Array.isArray(data))
|
if (Array.isArray(data))
|
||||||
{
|
{
|
||||||
let descriptor = data[0];
|
let descriptor = data[0];
|
||||||
|
@ -16,7 +21,7 @@ export function render(data, element)
|
||||||
|
|
||||||
if (typeof descriptor === "function")
|
if (typeof descriptor === "function")
|
||||||
{
|
{
|
||||||
render(descriptor(...args), element);
|
SuiWeb.render(descriptor(...args), element);
|
||||||
}
|
}
|
||||||
else if (typeof descriptor === "string")
|
else if (typeof descriptor === "string")
|
||||||
{
|
{
|
||||||
|
@ -31,7 +36,7 @@ export function render(data, element)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
render(arg, result);
|
SuiWeb.render(arg, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,4 +53,5 @@ export function render(data, element)
|
||||||
{
|
{
|
||||||
throw new SyntaxError();
|
throw new SyntaxError();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue