/// /** * TEST PATTERN: JSX is Automatically Reactive * * CLAIM: Within JSX, reactivity is automatic - you don't need computed() * SOURCE: folk_wisdom/reactivity.md, CELLS_AND_REACTIVITY.md * * WHAT THIS TESTS: * This pattern demonstrates that reactive values update automatically in JSX * without needing to wrap them in computed(). We test: * 1. Direct cell references update automatically * 2. Property access (user.name) updates automatically * 3. Inline expressions (count * 2) update automatically * 4. Array operations (items.length) update automatically * 5. Conditional expressions (ternary) work with reactive values * * EXPECTED BEHAVIOR: * When you click "Update All Values", all displayed values should update * immediately without any computed() wrappers. * * MANUAL VERIFICATION STEPS: * 1. Load the pattern * 2. Observe initial values: Count=0, User="Alice", Items=3 * 3. Click "Update All Values" * 4. Verify all values update: Count=1, User="Bob", Items=4, Status="Active" * 5. Click multiple times to verify continuous updates */ import { Cell, Default, handler, NAME, pattern, UI } from "commontools"; interface Item { title: string; } interface User { name: string; age: number; } interface TestInput { count: Default; user: Default; items: Default< Item[], [{ title: "Item 1" }, { title: "Item 2" }, { title: "Item 3" }] >; } const updateAllValues = handler< unknown, { count: Cell; user: Cell; items: Cell } >((_args, { count, user, items }) => { // Increment count count.set(count.get() + 1); // Toggle user name const currentUser = user.get(); user.update({ name: currentUser.name === "Alice" ? "Bob" : "Alice", }); // Add or remove an item const currentItems = items.get(); if (currentItems.length < 5) { items.push({ title: `Item ${currentItems.length + 1}` }); } else { items.set(currentItems.slice(0, 3)); } }); export default pattern(({ count, user, items }) => { return { [NAME]: "Test: JSX Automatic Reactivity", [UI]: (

JSX Automatic Reactivity Test

All values below use NO computed() - just direct references in JSX

{/* 1. Direct cell reference */}
Direct cell reference: Count = {count}
{/* 2. Property access */}
Property access: User name = {user.name}
{/* 3. Inline expression */}
Inline expression: Count x 2 = {count * 2}
{/* 4. Array operations */}
Array operations: Item count = {items.length}
{/* 5. Nested property access */}
Nested property: Age = {user.age}
{/* 6. Array mapping (reactive) */}
Array mapping:
    {items.map((item, i) =>
  • {item.title}
  • )}
Update All Values

What to observe:

  • Click the button and watch ALL values update simultaneously
  • No computed() wrappers are needed for any of these reactive updates
  • This demonstrates that JSX has built-in reactivity
), count, user, items, }; });