Compare commits

..

No commits in common. "8f488f48bd85f803128eda66c6dab00834a94aeb" and "e5fddf7a7d41c17b1ef02b8a5d64bc78175e9da2" have entirely different histories.

2 changed files with 20 additions and 44 deletions

View file

@ -67,7 +67,7 @@ export function App(game)
}, },
[ [
Board, Board,
{ board: game.board } game.board
], ],
[ [
"div", "div",
@ -83,13 +83,13 @@ export function App(game)
/** /**
* Renders an element which represents the specified {@link board `board`}. * Renders an element which represents the specified {@link board `board`}.
* *
* @param {{ board: Board }} board * @param {Board} board
* The board represented in this element. * The board represented in this element.
* *
* @returns {NodeDescriptor} * @returns {NodeDescriptor}
* The rendered element. * The rendered element.
*/ */
export function Board({ board }) export function Board(board)
{ {
let fields = board.flatMap((row) => row); let fields = board.flatMap((row) => row);
@ -99,7 +99,7 @@ export function Board({ board })
...fields.map( ...fields.map(
(field) => (field) =>
{ {
return /** @type {NodeDescriptor} */([Field, { field }]); return /** @type {NodeDescriptor} */([Field, field]);
}), }),
["div", { style: "clear: both;" }] ["div", { style: "clear: both;" }]
]; ];
@ -108,13 +108,13 @@ export function Board({ board })
/** /**
* Renders an element which represents the specified {@link field `field`}. * Renders an element which represents the specified {@link field `field`}.
* *
* @param {{ field: CellOwner }} field * @param {CellOwner} field
* The field to represent. * The field to represent.
* *
* @returns {NodeDescriptor} * @returns {NodeDescriptor}
* The rendered element. * The rendered element.
*/ */
export function Field({ field }) export function Field(field)
{ {
return [ return [
"div", "div",
@ -143,23 +143,23 @@ export function MenuBar()
return [ return [
"div", "div",
{ className: "menu-bar" }, { className: "menu-bar" },
[Button, { content: ["New Game", { className: newGameClass }] }], [Button, ["New Game", { className: newGameClass }]],
[Button, { content: ["Save Game", { className: saveGameClass }] }], [Button, ["Save Game", { className: saveGameClass }]],
[Button, { content: ["Load Game", { className: loadGameClass }] }], [Button, ["Load Game", { className: loadGameClass }]],
[Button, { content: ["Undo Last Move", { className: undoClass }] }] [Button, ["Undo Last Move", { className: undoClass }]]
]; ];
} }
/** /**
* Renders a button. * Renders a button.
* *
* @param {{ content: ElementDescriptor[1][] }} content * @param {...ElementDescriptor[1][]} content
* The settings of the button. * The settings of the button.
* *
* @returns {NodeDescriptor} * @returns {NodeDescriptor}
* The rendered element. * The rendered element.
*/ */
export function Button({ content }) export function Button(content)
{ {
return [ return [
"button", "button",

View file

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