Skip to content

feat(jarl-atoms)!: 420 — unionRouteAtom, and notAtom taking one route plus options - #110

Open
randomdevpete wants to merge 2 commits into
masterfrom
task-420-compound-atom-union-of-routes
Open

feat(jarl-atoms)!: 420 — unionRouteAtom, and notAtom taking one route plus options#110
randomdevpete wants to merge 2 commits into
masterfrom
task-420-compound-atom-union-of-routes

Conversation

@randomdevpete

Copy link
Copy Markdown
Owner

Adds unionRouteAtom, which combines several routes into one that matches wherever any member
does, and makes notAtom take that single (possibly union) route plus an options object instead
of a spread.

Needs OWNER's attention:

  • The union prefers the member that matched exactly, falling back to the first that matches.
    Plain first-match-wins is a live regression: the docs site's not-found list starts with
    homeRoute (rootAtom), which matches everywhere, so the whole site would report not-found.
  • NotOptions.exact defaults to true, unlike <Route exact> and useLink({ exact }), which
    default to false. It has to, to preserve current behaviour — but it is the one place in the
    surface where exact defaults the other way.

BREAKING CHANGE: notAtom no longer takes a spread of routes. Combine them with
unionRouteAtom([...]) first, then pass the result as the single first argument.

Why unionRouteAtom: the return type is a route atom (readable for a RouteReturn, writable
to navigate, usable as a parent), so it takes the RouteAtom suffix; union names what it does
without implying a boolean like notAtom's bare form does.

A route that matches wherever any of its members does, and exactly wherever any
member matches exactly. `values`, `rest` and `reverse` come from the member that
actually matched — the exact one where there is one, so an ancestor that matches
every location beneath it never shadows the leaf that rendered, and only the
non-exact fallback depends on the order given.

Because it is a `RouteAtom` and not a boolean, it composes: as another route's
`parent`, in `<Route on={...}>`, or as a whole route list handed to `notAtom`.
Its `values` are the union of its members', via a new `RouteValues` type, so a
chain of increasingly specific routes reads as one route bound to a union of
their params.

A union has no URL shape of its own, so `reverse` and writes go to whichever
member matches and to the first listed when none does.

Ticket: 420
The variadic first param was the only thing standing between `notAtom` and a
second argument, and with `unionRouteAtom` the whole route list is expressible
as one route, so the spread buys nothing. `notAtom(unionRouteAtom([...]))`
replaces `notAtom(...routes)`, and the exactness the old signature hard-coded
becomes the option the freed-up slot allows: `{ exact: false }` counts an
ancestor match too. It still defaults to true, because an ancestor is
`match: true` for every location beneath it and only the leaf's exactness says
whether anything was found.

BREAKING CHANGE: `notAtom` takes a single route atom rather than a spread of
them. Combine several with `unionRouteAtom([...])` first.

Ticket: 420
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