Add key field to UElement (ADR-004)

This commit is contained in:
2026-05-18 16:39:14 +00:00
parent c9c32a6aa6
commit 822ded6cf1
3 changed files with 61 additions and 2 deletions

View File

@@ -3,7 +3,8 @@ import type { UNode, UElement, URoot, UType, UComponent, UniversalProps } from "
let _idCounter = 0;
export function h(type: UType, props?: UniversalProps | null, ...children: UNode[]): UElement | URoot {
const resolvedProps: UniversalProps = props ? { ...props } : {};
const { key, ...restProps } = props ?? {};
const resolvedProps: UniversalProps = restProps;
const flatChildren = children.flat(Infinity as 1).filter((c: UNode) => c != null && c !== false) as UNode[];
if (type === "root") {
@@ -18,6 +19,7 @@ export function h(type: UType, props?: UniversalProps | null, ...children: UNode
type: type as string,
props: resolvedProps,
children: flatChildren,
...(key != null ? { key: key as string } : {}),
} as UElement;
}