feat(docs): 678 — routing demo that switches on a page route atom - #108
Draft
randomdevpete wants to merge 1 commit into
Draft
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A deliberately minimal routing demo: one route atom holds which of a fixed set of pages the URL
names, a plain
switchon its value picks the component to render, and the nav buttons navigate bysetting that atom instead of rendering
<Link>s. It imports nothing fromjarl-react— noLink,RouteorSwitchcomponent appears anywhere inSwitchRoutingApp.tsx.The
setRouteAtomquestionThe ticket left open whether to add a
setRouteAtomprimitive tojarl-atomsor approximate thesame shape with existing pieces. This PR approximates it: the fixed-set page segment is a
paramRouteAtomnarrowed by atransformRouteAtom, the same compositionnumericRouteAtom's owndocstring calls "the usual way to build a constrained segment from the existing primitives". The
explicit generics on that
transformRouteAtomcall (<{ page: string }, { page: SwitchRoutingPage }>) are load-bearing: they pin the atom's value to theSwitchRoutingPageunion rather than lettingit widen to
string, which is what lets theswitchinpageViewbe exhaustive with nodefaultcase. Confirmed by typechecking the branch directly (
tscreports no errors on the new files, and thesame pre-existing, unrelated errors — missing
@emotion/styled/highlight.jstypes, a generatedsource-files.json— appear identically on the base branch).No new export was added to
jarl-atoms.setRouteAtomcollides with jotai's own write vocabulary —this demo already calls
useSetAtom(pageRoute), anduseSetAtom(setRouteAtom(...))would fightitself — and the base branch (#97) already composes constrained segments the same way, locally, for
its own demo (
dateSegmentRouteAtom/filenameRouteAtominComplexRoutingApp.tsx, neitherexported).
Ticket 927 tracks a properly-named
oneOfRouteAtomprimitive forjarl-atoms, filed to land once789 does.
Stack
Stacked on #97 (ticket 677), which this ticket depends on. Targets
task-677-complex-routing-demo-custom-path-atoms, notmaster.