Repository navigation
docs(scoped-atoms): data tables as the page's examples - #46
Merged
Merged
Conversation
The scoped-atoms page's examples are now an admin page's tables: Orders and Customers each provide their own state with Table.provide(), and their toolbar, header, rows and footer find it with Table.use(). An order expands to show its line items as a table inside the Orders table, for the nearest-provider section. An X-ray outlines each providing table. A note says when a family keyed by a table id fits instead, and a new "Using both" section shows a family provided by a scoped atom. "Values from the server" moves to the Hydration page, rewritten. BrowserFrame can frame a single page with a fixed address. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jarrednorrisdev
force-pushed
the
docs/scoped-examples
branch
from
October 10, 2026 00:30
28e30e8 to
aac42e8
Compare
jarrednorrisdev
marked this pull request as ready for review
October 10, 2026 00:30
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.
Reworks the scoped-atoms docs page around one realistic example: data tables on an admin page. Builds on #45, now merged. Rebuilt as a single commit on
main.Background: a scoped atom gives each instance of a component its own atom: the component calls
Table.provide(), and any component below it reads that atom withTable.use(), like Svelte context. The page used two note editors for this, which raised more questions than it answered ("why not a family keyed by note id?", "what app has two editors mirroring each other?"). A data table answers them: its toolbar, header, rows and footer are separate components sharing one search, sort, page and selection, and an admin page often has several tables.Example 1: two tables on one page
Sorting, searching, selecting or paging in one table leaves the other alone. The page shows this in a pretend browser window (the kit's
BrowserFrame). An X-ray button outlines each table that provides its own state, taggedOrders: Table.provide(), and each table's atom is labelled by its table, so the page's atom graph shows "Orders table" and "Customers table".A note under the example answers "why not a family keyed by a table id?": a family needs someone to invent unique ids and pass them to every part, while a scoped atom's identity is the table component itself and its state lives exactly as long as the table. A family fits when the state should belong to the id, such as a sort remembered for the Orders table after navigating away.
Example 2: line items inside an order (nearest provider)
An order expands to show its line items as a smaller table inside the Orders table, so both provide
Table. The line items' parts call the sameTable.use()and get the line items' state, the nearest provider's. Collapsing the order and expanding it again starts its table afresh, because the table remounted.Also on the page
Tableinstead ofDraft.Table.use(). The snippet says it's a variant ofTablethat takes the table's name instead of its rows. The family decides identity and lifetime; the scoped atom decides who can reach it. It ends with a pointer to server-rendered data, the most common case for the combination.Tests
e2e/demo.test.ts, "each table provides its own state": sorting, searching, selecting and paging in one table leave the other alone, and the X-ray tags each table.e2e/features-atoms.test.ts, "use finds the nearest provider": the line items keep their own selection and sort inside the Orders table, and start afresh after the order is collapsed and expanded again.Locally, both pass in Chromium, and the two shell tests that load this page pass in Chromium and WebKit. The page has no console errors in light or dark mode, at desktop or phone width. Format, lint and type checks pass.
Decisions
BrowserFramecan now frame a single page with a fixedaddress, beside its existing multi-page mode.Where to look in the diff
apps/demo/src/routes/scoped-atoms/:table-scope.ts: theTablescoped atom, andvisibleRows.data-table.svelte: the table that provides it;table-toolbar.svelte,table-header.svelte,table-rows.svelteandtable-footer.svelteare its parts.admin.svelteandorder-items.svelte: the two examples, withadmin-data.ts.site.svelteandxray.svelte.ts: presentation only (the browser window and the X-ray), outside the shown code.+page.md: the prose.apps/demo/src/routes/hydration/+page.md: the new "Scoped atoms" subsection;troubleshooting/+page.md: its link.apps/demo/src/lib/docs/kit/browser-frame.svelte: the optionaladdress.apps/demo/e2e/demo.test.tsandfeatures-atoms.test.ts.🤖 Generated with Claude Code