Skip to content

Commit 00f84fe

Browse files
committed
Sync tsx-frontend/ to the frontend: async refusal whatever the name, tracker findIndex and optimistic list
Same exclusions and in-tree rewiring as before. Async callbacks declared in a component are refused (issue #20) whatever their name. The tracker demo locates the issue with findIndex (lowered to RX's predicate indexOf) and writes the claim into an optimistic copy of the list, so the row shows its real assignee. verify:subset: 26 tests.
1 parent f1db5a4 commit 00f84fe

8 files changed

Lines changed: 73 additions & 55 deletions

File tree

‎tsx-frontend/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ sh ref/scripts/solid-next.sh # repository root: clone and build Solid at ref/S
3434
(cd ref && npm install) # upstream's own dependencies, used through #rx/*
3535
cd tsx-frontend
3636
npm install
37-
npm run verify:subset # typecheck, boundary, paired counter, composition, tracker demo, stale write-back: 25 tests
37+
npm run verify:subset # typecheck, boundary, paired counter, composition, tracker demo, stale write-back: 26 tests
3838
```
3939

4040
## Layout (workspace `/Users/devagr/rx-tsx-refresh`)

‎tsx-frontend/baselines/coverage-manifest.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@
552552
"tsx/boundary.test.ts :: ordinary async callbacks are refused at their authored async node on every resolved callback route (issue #20)",
553553
"tsx/boundary.test.ts :: actions refuse async functions and async generators with synchronous-generator guidance (issue #20)",
554554
"tsx/boundary.test.ts :: explicit generator actions and async memo/server computations stay accepted beside the refusal (issue #20)",
555+
"tsx/boundary.test.ts :: async callbacks are refused whatever their name; nested synchronous components keep their own refusal (issue #20)",
555556
"tsx/paired.test.ts :: paired counter: TSX and RX have the same canonical semantic facts",
556557
"tsx/paired.test.ts :: paired counter: a different read mode is a fact difference, not normalized away",
557558
"tsx/paired.test.ts :: paired counter: interpreter, compiled and native frames agree",

‎tsx-frontend/docs/SUBSET.md‎

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,25 @@ and the coverage manifest records their new paths.
8282

8383
`tsx/demo.test.ts` uses `fixtures/demo/tracker.tsx` and its handwritten RX
8484
counterpart `tracker.rx`: a demo for review, not a broader parity claim. It
85-
combines a `createStore` issue list with a draft path write, a filter signal with
86-
`createMemo` views (visible rows, open count), `<For>` rows inside a `<Show>`
87-
with an empty-state fallback, a later-declared `IssueRow` child with props and an
88-
`onAssign` callback, and an explicit generator action whose `createOptimistic`
89-
claim shows at once, commits the yielded `assignIssue(id)` answer on success, and
90-
rolls back with a status message on failure. The tests require equal canonical
91-
checker facts (and that snapshotting the filter in the RX is detected), and the
92-
same eight exact frames from native Solid's universal renderer, the RX compiler for
93-
both programs, and the RX interpreter for both programs, across a scripted session:
94-
initial render, a failed assignment with rollback, a filter change, two successful
95-
assignments, and the empty-state fallback. Requests are controllable flights; a
96-
repeated request for the same issue would reuse its cached answer on every backend,
97-
so the script never retries one issue. Async list loading, async memos and server
98-
functions are deliberately left out.
85+
combines a `createStore` issue list with a draft path write located by
86+
`findIndex` (lowered to RX's predicate `indexOf`, which both RX runtimes define as
87+
`findIndex`), a filter signal with `createMemo` views (visible rows, open count),
88+
`<For>` rows inside a `<Show>` with an empty-state fallback, a later-declared
89+
`IssueRow` child with props and an `onAssign` callback, and an explicit generator
90+
action that writes the claim into an optimistic copy of the list
91+
(`createOptimistic(() => issues.list)`), commits the yielded `assignIssue(id)`
92+
answer to the store on success, and rolls back with a status message on failure.
93+
The tests require equal canonical checker facts (and that snapshotting the filter
94+
in the RX is detected), and the same eight exact frames from native Solid's
95+
universal renderer, the RX compiler for both programs, and the RX interpreter for
96+
both programs: a successful claim shown at once and committed, a failed claim
97+
rolled back, a filter change, and a claim that empties the open view into its
98+
fallback. The script never repeats a request with the same arguments. Each such
99+
call is a new request in Solid and in RX (SF-2c: "two calls with the same arguments
100+
are two requests"), but the RX interpreter's scenario model makes every `./api`
101+
function "a flight keyed by its arguments" (ref/src/runtime.ts), so a retry would
102+
reuse the first answer there for a harness reason. Async list loading, async memos
103+
and server functions are deliberately left out.
99104

100105
## Stale Write-Back (AC-1e)
101106

‎tsx-frontend/tsx/boundary.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,12 @@ test("explicit generator actions and async memo/server computations stay accepte
176176
assert.doesNotThrow(() => lowerTsx(asyncCounter("const value = createMemo(async (): Promise<number> => await request(n()));", "<button onClick={() => setN(1)}>{value()}</button>")));
177177
assert.doesNotThrow(() => lowerTsx('import { serverFunction, createServerMemo } from "reactivescript-tsx";\nexport function Counter() {\n const load = serverFunction("load", function* (n: number): Generator<unknown, number, number> { return n + 1; });\n const value = createServerMemo(async () => await load(0));\n return <span>{value()}</span>;\n}'));
178178
});
179+
180+
test("async callbacks are refused whatever their name; nested synchronous components keep their own refusal (issue #20)", () => {
181+
const asyncSave = "async function Save() { const result: number = await request(); setN(result); }";
182+
refusedAt(asyncCounter(asyncSave, "<button onClick={() => Save()}>{n()}</button>"), "async function Save", ASYNC_CALLBACK);
183+
refusedAt(asyncCounter("async function Save() { await request(); }", "<button onClick={Save}>{n()}</button>"), "async function Save", ASYNC_CALLBACK);
184+
refusedAt(asyncCounter("const Save = async () => { await request(); };", "<button onClick={() => Save()}>{n()}</button>"), "async () =>", ASYNC_CALLBACK);
185+
refusedAt(asyncCounter("function Badge() { return <i>x</i>; }", untouched), "function Badge",
186+
"Nested component declarations are unsupported; use module components");
187+
});

‎tsx-frontend/tsx/demo.test.ts‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ type Answer = Extract<Step, { answer: number }>;
2929
type Driver = { frame: () => string; click: (n: number) => void; answer: (step: Answer) => void; settle: () => Promise<void>; dispose: () => void };
3030

3131
const SCRIPT: Step[] = [
32-
{ click: 2 }, // take "Slow search": the claim shows at once
32+
{ click: 1 }, // take "Crash on save": the claim shows at once as "me"
33+
{ answer: 1, owner: "dev" }, // success commits the server's owner
34+
{ click: 2 }, // take "Slow search"
3335
{ answer: 2, failure: "offline" }, // the request fails: roll back to "ana" and explain
3436
{ click: 0 }, // filter to open issues
35-
{ click: 1 }, // take "Crash on save"
36-
{ answer: 1, owner: "dev" }, // success commits the owner; the row leaves the open view
37-
{ click: 1 }, // take "Typo in footer"
38-
{ answer: 3, owner: "dev" }, // success: nothing open, so the fallback shows
37+
{ click: 1 }, // take "Typo in footer": it leaves the open view at once
38+
{ answer: 3, owner: "dev" }, // success: nothing open, so the fallback stays
3939
];
4040
const EXPECTED = [
4141
"Filter: all2 openCrash on save: nobodytakeSlow search: anatakeTypo in footer: nobodytake",
42-
"Filter: all2 openCrash on save: nobodytakeSlow search: metakeTypo in footer: nobodytake",
43-
"Filter: all2 openCrash on save: nobodytakeSlow search: anatakeTypo in footer: nobodytakeCould not assign #2",
44-
"Filter: open2 openCrash on save: nobodytakeTypo in footer: nobodytakeCould not assign #2",
45-
"Filter: open2 openCrash on save: metakeTypo in footer: nobodytakeCould not assign #2",
46-
"Filter: open1 openTypo in footer: nobodytake",
47-
"Filter: open1 openTypo in footer: metake",
42+
"Filter: all1 openCrash on save: metakeSlow search: anatakeTypo in footer: nobodytake",
43+
"Filter: all1 openCrash on save: devtakeSlow search: anatakeTypo in footer: nobodytake",
44+
"Filter: all1 openCrash on save: devtakeSlow search: metakeTypo in footer: nobodytake",
45+
"Filter: all1 openCrash on save: devtakeSlow search: anatakeTypo in footer: nobodytakeCould not assign #2",
46+
"Filter: open1 openTypo in footer: nobodytakeCould not assign #2",
47+
"Filter: open0 openNothing to triageCould not assign #2",
4848
"Filter: open0 openNothing to triage",
4949
];
5050

@@ -136,7 +136,7 @@ test("demo tracker: TSX and handwritten RX have the same canonical checker facts
136136
assert.ok(memo.some(c => c.reads.some(r => r.endsWith("::source:mode tracked"))), "the visible rows track the filter");
137137
const claim = computations.find(c => c.kind === "action");
138138
assert.ok(claim, "claim is an explicit action");
139-
assert.ok(claim.writes.some(w => w.endsWith("::source:claiming? optimistic")), "the claim is an optimistic write");
139+
assert.ok(claim.writes.some(w => w.endsWith("::source:shown? optimistic")), "the claim is an optimistic write to the shown list");
140140
assert.ok(claim.writes.some(w => w.endsWith("::source:issues write path")), "success writes the store path");
141141
assert.ok(claim.calls.some(c => c.endsWith("::import:assignIssue!io")), "the action calls the request");
142142
assert.ok(computations.some(c => c.kind === "handler" && c.at === "IssueRow onAssign" && c.calls.some(x => x.endsWith("::action:claim!io"))),

‎tsx-frontend/tsx/fixtures/demo/tracker.rx‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ export default component Tracker() {
88
{ id: 3, title: "Typo in footer", assignee: "" },
99
],
1010
};
11+
source shown = issues.list;
1112
source mode := "all";
12-
source claiming = 0;
1313
source status := "";
1414

15-
visible = filter(issues.list, issue => mode == "all" || issue.assignee == "");
16-
unassigned = filter(issues.list, issue => issue.assignee == "").length;
15+
visible = filter(shown, issue => mode == "all" || issue.assignee == "");
16+
unassigned = filter(shown, issue => issue.assignee == "").length;
1717

1818
action claim(id: number) {
19-
optimistic claiming := id;
19+
optimistic shown := list => map(list, issue => issue.id == id ? { id: issue.id, title: issue.title, assignee: "me" } : issue);
2020
try {
2121
let owner = await assignIssue(id);
22-
issues.list[id - 1].assignee := owner;
22+
issues.list[indexOf(issues.list, issue => issue.id == id)].assignee := owner;
2323
status := "";
2424
} catch (error) {
2525
status := "Could not assign #" + id;
@@ -30,12 +30,12 @@ export default component Tracker() {
3030
<button onClick={() => { mode := mode == "all" ? "open" : "all" }}>Filter: {mode}</button>
3131
<b>{"" + unassigned} open</b>
3232
{if visible.length > 0 {
33-
for issue in visible { <IssueRow issue={issue} claiming={claiming == issue.id} onAssign={() => { claim(issue.id) }}/> }
33+
for issue in visible { <IssueRow issue={issue} onAssign={() => { claim(issue.id) }}/> }
3434
} else { <i>Nothing to triage</i> }}
3535
<em>{status}</em>
3636
</section>
3737
}
3838

39-
component IssueRow(props: { issue: { id: number; title: string; assignee: string }; claiming: boolean; onAssign: action catches(nothing) }) {
40-
<p>{props.issue.title}: {if props.claiming { {"me"} } else { {props.issue.assignee || "nobody"} }}<button onClick={() => { props.onAssign() }}>take</button></p>
39+
component IssueRow(props: { issue: { id: number; title: string; assignee: string }; onAssign: action catches(nothing) }) {
40+
<p>{props.issue.title}: {props.issue.assignee || "nobody"}<button onClick={() => { props.onAssign() }}>take</button></p>
4141
}

‎tsx-frontend/tsx/fixtures/demo/tracker.tsx‎

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,25 @@ export default function Tracker() {
99
{ id: 3, title: "Typo in footer", assignee: "" },
1010
],
1111
});
12+
// What the list shows: the stored issues, plus any claim still waiting on the server.
13+
const [shown, setShown] = createOptimistic(() => issues.list);
1214
const [mode, setMode] = createSignal("all");
13-
const [claiming, setClaiming] = createOptimistic(() => 0);
1415
const [status, setStatus] = createSignal("");
1516

1617
const visible = createMemo(() =>
17-
issues.list.filter((issue) => mode() === "all" || issue.assignee === ""),
18+
shown().filter((issue) => mode() === "all" || issue.assignee === ""),
1819
);
19-
const unassigned = createMemo(() => issues.list.filter((issue) => issue.assignee === "").length);
20+
const unassigned = createMemo(() => shown().filter((issue) => issue.assignee === "").length);
2021

2122
// Show the claim at once; commit the server's answer, or roll back and explain.
2223
const claim = action(function* (id: number) {
23-
setClaiming(id);
24+
setShown((list) =>
25+
list.map((issue) => (issue.id === id ? { id: issue.id, title: issue.title, assignee: "me" } : issue)),
26+
);
2427
try {
2528
const owner: string = yield assignIssue(id);
2629
setIssues((draft) => {
27-
draft.list[id - 1].assignee = owner; // ids are 1-based list positions here
30+
draft.list[draft.list.findIndex((issue) => issue.id === id)].assignee = owner;
2831
});
2932
setStatus("");
3033
} catch (error) {
@@ -37,25 +40,17 @@ export default function Tracker() {
3740
<button onClick={() => setMode(mode() === "all" ? "open" : "all")}>Filter: {mode()}</button>
3841
<b>{unassigned()} open</b>
3942
<Show when={visible().length > 0} fallback={<i>Nothing to triage</i>}>
40-
<For each={visible()}>
41-
{(issue) => (
42-
<IssueRow issue={issue} claiming={claiming() === issue.id} onAssign={() => claim(issue.id)} />
43-
)}
44-
</For>
43+
<For each={visible()}>{(issue) => <IssueRow issue={issue} onAssign={() => claim(issue.id)} />}</For>
4544
</Show>
4645
<em>{status()}</em>
4746
</section>
4847
);
4948
}
5049

51-
function IssueRow(props: {
52-
issue: { id: number; title: string; assignee: string };
53-
claiming: boolean;
54-
onAssign: () => void;
55-
}) {
50+
function IssueRow(props: { issue: { id: number; title: string; assignee: string }; onAssign: () => void }) {
5651
return (
5752
<p>
58-
{props.issue.title}: {props.claiming ? "me" : props.issue.assignee || "nobody"}
53+
{props.issue.title}: {props.issue.assignee || "nobody"}
5954
<button onClick={() => props.onAssign()}>take</button>
6055
</p>
6156
);

‎tsx-frontend/tsx/lower.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,8 @@ export function lowerTsx(
421421
names: Set<string>,
422422
into = functions,
423423
) => {
424-
// A named async function inside a component is a stored callback, refused with the same guidance.
425-
if (fn.async && into !== functions && fn.id && !/^[A-Z]/.test(fn.id.name))
424+
// A named async function inside a component is a stored callback, refused with the same guidance whatever its name.
425+
if (fn.async && into !== functions)
426426
return asyncCallback(fn);
427427
if (
428428
!fn.id ||
@@ -1193,9 +1193,13 @@ export function lowerTsx(
11931193
!n.callee.computed &&
11941194
!n.callee.optional &&
11951195
n.callee.property.type === "Identifier" &&
1196-
["filter", "every", "map"].includes(n.callee.property.name)
1196+
["filter", "every", "map", "findIndex"].includes(n.callee.property.name)
11971197
) {
1198-
const method = n.callee.property.name;
1198+
// findIndex lowers to RX's predicate indexOf(xs, f), which both RX runtimes define as xs.findIndex(f).
1199+
const method =
1200+
n.callee.property.name === "findIndex"
1201+
? "indexOf"
1202+
: n.callee.property.name;
11991203
const array = value(n.callee.object, scope);
12001204
if (array.shape.kind !== "array" || n.arguments.length !== 1)
12011205
return fail(
@@ -1259,6 +1263,8 @@ export function lowerTsx(
12591263
shape:
12601264
method === "every"
12611265
? { kind: "boolean" }
1266+
: method === "indexOf"
1267+
? { kind: "number" }
12621268
: method === "map"
12631269
? { kind: "array", item: predicate.shape }
12641270
: array.shape,
@@ -4166,6 +4172,8 @@ export function lowerTsx(
41664172
return fail(fn, "Functions must end with one value/JSX return");
41674173
for (const node of nodes.slice(0, -1))
41684174
if (node.type === "FunctionDeclaration") {
4175+
// An async declaration is a callback, refused as one before the nested-component check (issue #20).
4176+
if (node.async) return asyncCallback(node);
41694177
if (!node.id || /^[A-Z]/.test(node.id.name))
41704178
return fail(
41714179
node,

0 commit comments

Comments
 (0)