Implement fragment support
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
53a11eccf6
commit
0202946813
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@denreg-jsx",
|
"name": "@denreg-jsx",
|
||||||
"version": "0.1.1",
|
"version": "0.1.2",
|
||||||
"description": "Denreg JSX renderer",
|
"description": "Denreg JSX renderer",
|
||||||
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
||||||
"contributors": [],
|
"contributors": [],
|
||||||
|
17
jsx/mod.ts
17
jsx/mod.ts
@ -12,7 +12,7 @@ declare namespace JSX {
|
|||||||
export { Fragment };
|
export { Fragment };
|
||||||
|
|
||||||
export type Element = {
|
export type Element = {
|
||||||
component: Component | string;
|
component: Component | string | typeof Fragment;
|
||||||
props: any;
|
props: any;
|
||||||
children: any[];
|
children: any[];
|
||||||
};
|
};
|
||||||
@ -38,7 +38,10 @@ export async function renderSSR(element: Element | string): Promise<string> {
|
|||||||
if (typeof element === "string") return element;
|
if (typeof element === "string") return element;
|
||||||
else if (typeof element.component === "string")
|
else if (typeof element.component === "string")
|
||||||
return await renderHTML(element as Element);
|
return await renderHTML(element as Element);
|
||||||
else if (typeof element.component === "function")
|
else if (
|
||||||
|
typeof element.component === "function" ||
|
||||||
|
element.component === Fragment
|
||||||
|
)
|
||||||
return await renderCustom(element as Element);
|
return await renderCustom(element as Element);
|
||||||
|
|
||||||
console.warn("renderSSR: invalid element", element);
|
console.warn("renderSSR: invalid element", element);
|
||||||
@ -112,6 +115,15 @@ async function renderCustom(element: Element) {
|
|||||||
if (typeof element.component === "string")
|
if (typeof element.component === "string")
|
||||||
throw new Error("Internal consistency error");
|
throw new Error("Internal consistency error");
|
||||||
|
|
||||||
|
if (element.component === Fragment) {
|
||||||
|
const ch = (
|
||||||
|
await Promise.all(
|
||||||
|
cleanChildren(element.children).map((child) => renderSSR(child))
|
||||||
|
)
|
||||||
|
).join("");
|
||||||
|
|
||||||
|
return ch;
|
||||||
|
} else {
|
||||||
const res = await Promise.resolve(
|
const res = await Promise.resolve(
|
||||||
element.component(
|
element.component(
|
||||||
{
|
{
|
||||||
@ -128,3 +140,4 @@ async function renderCustom(element: Element) {
|
|||||||
|
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -23,7 +23,7 @@ export { Marked } from "https://deno.hibas123.de/raw/markdown/mod.ts";
|
|||||||
|
|
||||||
import DS from "https://raw.githubusercontent.com/hibas123/dndb/master/mod.ts";
|
import DS from "https://raw.githubusercontent.com/hibas123/dndb/master/mod.ts";
|
||||||
|
|
||||||
import * as Pico from "https://deno.hibas123.de/raw/@denreg-jsx@0.1.1/mod.ts";
|
import * as Pico from "https://deno.hibas123.de/raw/@denreg-jsx@0.1.2/mod.ts";
|
||||||
|
|
||||||
export { Pico };
|
export { Pico };
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user