From e18fd1945360c05447b25c37f18a4b2c1d9c7cd4 Mon Sep 17 00:00:00 2001 From: "glm-5.1" Date: Thu, 21 May 2026 20:48:59 +0000 Subject: [PATCH] Implement Parallel ujsx component with id and maxConcurrency props --- src/component/index.ts | 3 ++- src/component/parallel.ts | 27 +++++++++++++++++++++++- test/component/components.test.ts | 34 +++++++++++++++++++++++++++---- 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/src/component/index.ts b/src/component/index.ts index 8cec2e9..216486a 100644 --- a/src/component/index.ts +++ b/src/component/index.ts @@ -1 +1,2 @@ -export {}; \ No newline at end of file +export { Parallel } from "./parallel.js"; +export type { ParallelProps } from "./parallel.js"; \ No newline at end of file diff --git a/src/component/parallel.ts b/src/component/parallel.ts index 8cec2e9..ab4f157 100644 --- a/src/component/parallel.ts +++ b/src/component/parallel.ts @@ -1 +1,26 @@ -export {}; \ No newline at end of file +import type { UComponent, UElement, UNode, UniversalProps } from "@alkdev/ujsx"; + +export interface ParallelProps extends UniversalProps { + id?: string; + maxConcurrency?: number; +} + +export const Parallel: UComponent = ( + props: ParallelProps & { children?: UNode[] }, +): UElement => { + const { id, maxConcurrency, children, ...rest } = props; + const elementProps: UniversalProps = { ...rest }; + if (id !== undefined) { + elementProps.id = id; + } + if (maxConcurrency !== undefined) { + elementProps.maxConcurrency = maxConcurrency; + } + return { + type: "parallel", + props: elementProps, + children: children ?? [], + }; +}; + +Parallel.displayName = "Parallel"; \ No newline at end of file diff --git a/test/component/components.test.ts b/test/component/components.test.ts index 731c880..f9ee49a 100644 --- a/test/component/components.test.ts +++ b/test/component/components.test.ts @@ -1,7 +1,33 @@ -import { describe, it, expect } from 'vitest'; +import { describe, it, expect } from "vitest"; +import { Parallel } from "../../src/component/parallel.js"; +import type { ParallelProps } from "../../src/component/parallel.js"; +import type { UElement, UNode } from "@alkdev/ujsx"; -describe('components', () => { - it('placeholder', () => { - expect(true).toBe(true); +describe("Parallel", () => { + it("produces UElement with type parallel", () => { + const el = Parallel({} as ParallelProps & { children?: UNode[] }); + expect(el.type).toBe("parallel"); + expect(el.children).toEqual([]); + }); + + it("preserves id prop", () => { + const el = Parallel({ id: "group-1" } as ParallelProps & { children?: UNode[] }); + expect((el as UElement).props.id).toBe("group-1"); + }); + + it("preserves maxConcurrency prop", () => { + const el = Parallel({ maxConcurrency: 3 } as ParallelProps & { children?: UNode[] }); + expect((el as UElement).props.maxConcurrency).toBe(3); + }); + + it("includes children", () => { + const el = Parallel({ children: ["child1", "child2"] } as ParallelProps & { children?: UNode[] }); + expect(el.children).toEqual(["child1", "child2"]); + }); + + it("omits id and maxConcurrency when not provided", () => { + const el = Parallel({} as ParallelProps & { children?: UNode[] }); + expect((el as UElement).props.id).toBeUndefined(); + expect((el as UElement).props.maxConcurrency).toBeUndefined(); }); }); \ No newline at end of file