import { computed, type Default, handler, NAME, pattern, UI, type VNode, Writable, } from "commonfabric"; // Fixture for the cf-render handler-child test. The parent's body instantiates // no child; a handler creates each one and keeps it in a list, and the parent // shows each through `cf-render`. Starting the parent therefore starts no // child, so a child computes in a runtime only if something there starts it. interface ChildInput { n: Default; } interface ChildOutput { [NAME]: string; [UI]: VNode; n: number; doubled: number; } const Child = pattern(({ n }) => { const doubled = computed(() => n * 2); return { [NAME]: "handler child", [UI]: doubled {doubled}, n, doubled, }; }); interface ParentInput { children: Writable>; } interface ParentOutput { [NAME]: string; [UI]: VNode; children: ChildOutput[]; addChild: unknown; } const addChild = handler }>( (_, { children }) => { children.push(Child({ n: 1 })); }, ); export default pattern(({ children }) => { return { [NAME]: "handler child parent", [UI]: (
{children.map((child) => )}
), children, addChild: addChild({ children }), }; });