Skip to content

feat(docs): 678 — routing demo that switches on a page route atom - #108

Draft
randomdevpete wants to merge 1 commit into
task-677-complex-routing-demo-custom-path-atomsfrom
task-678-very-simple-logic-switch-routing-demo
Draft

feat(docs): 678 — routing demo that switches on a page route atom#108
randomdevpete wants to merge 1 commit into
task-677-complex-routing-demo-custom-path-atomsfrom
task-678-very-simple-logic-switch-routing-demo

Conversation

@randomdevpete

Copy link
Copy Markdown
Owner

Summary

A deliberately minimal routing demo: one route atom holds which of a fixed set of pages the URL
names, a plain switch on its value picks the component to render, and the nav buttons navigate by
setting that atom instead of rendering <Link>s. It imports nothing from jarl-react — no Link,
Route or Switch component appears anywhere in SwitchRoutingApp.tsx.

The setRouteAtom question

The ticket left open whether to add a setRouteAtom primitive to jarl-atoms or approximate the
same shape with existing pieces. This PR approximates it: the fixed-set page segment is a
paramRouteAtom narrowed by a transformRouteAtom, the same composition numericRouteAtom's own
docstring calls "the usual way to build a constrained segment from the existing primitives". The
explicit generics on that transformRouteAtom call (<{ page: string }, { page: SwitchRoutingPage }>) are load-bearing: they pin the atom's value to the SwitchRoutingPage union rather than letting
it widen to string, which is what lets the switch in pageView be exhaustive with no default
case. Confirmed by typechecking the branch directly (tsc reports no errors on the new files, and the
same pre-existing, unrelated errors — missing @emotion/styled/highlight.js types, a generated
source-files.json — appear identically on the base branch).

No new export was added to jarl-atoms. setRouteAtom collides with jotai's own write vocabulary —
this demo already calls useSetAtom(pageRoute), and useSetAtom(setRouteAtom(...)) would fight
itself — and the base branch (#97) already composes constrained segments the same way, locally, for
its own demo (dateSegmentRouteAtom/filenameRouteAtom in ComplexRoutingApp.tsx, neither
exported).

Ticket 927 tracks a properly-named oneOfRouteAtom primitive for jarl-atoms, filed to land once
789 does.

Stack

Stacked on #97 (ticket 677), which this ticket depends on. Targets
task-677-complex-routing-demo-custom-path-atoms, not master.

A deliberately minimal demo: one route atom holds which of a fixed set of
pages the URL names, a plain `switch` on its value picks the component, and
the nav buttons navigate by writing that atom. It imports nothing from
`jarl-react` - no `Link`, `Route` or `Switch` component anywhere in it.

The fixed set is composed from existing exports rather than a new primitive:
a `paramRouteAtom` narrowed by a `transformRouteAtom`, the same composition
`numericRouteAtom` documents, which also types the value as the union the
switch needs so its cases are exhaustive.

Ticket: 678
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant