initial jsx support
This commit is contained in:
parent
2301c5d631
commit
11be5e979c
7 changed files with 77 additions and 30 deletions
29
src/jsx.ts
Normal file
29
src/jsx.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
* Copyright (c) 2025 xwra
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { html, type HtmlProxy } from "./html.ts";
|
||||
import { ChunkedStream } from "./stream.ts";
|
||||
|
||||
let context;
|
||||
|
||||
export function jsx(
|
||||
tag: string | typeof Fragment,
|
||||
{ children }: Record<string, any> = {},
|
||||
) {
|
||||
return async (chunks: ChunkedStream<string>) => {
|
||||
if (tag === Fragment) {
|
||||
context = html(chunks);
|
||||
for (const child of children) {
|
||||
await context.render?.(child);
|
||||
}
|
||||
return;
|
||||
}
|
||||
await (context ||= html(chunks))[tag](...children);
|
||||
};
|
||||
}
|
||||
|
||||
export const Fragment = Symbol("Fragment");
|
||||
|
||||
export const jsxs = jsx;
|
||||
Loading…
Add table
Add a link
Reference in a new issue