Mental model
After this page you should be able to answer: "Where does this value belong? Who should do this?"
Three roles, no overlap
Browser Server (Rust)
────────────────────────────────────── ─────────────────────────────
Template attributes data-linker-* / data-state-*
│ which method + arguments
▼
linker.js ───────── JSON ─────────────────────▶ LinkerComponent::call
▲ │
└──────────── data + pipeline ◀───────────────────┘
│ data │ pipeline
▼ ▼
state.js (client memory) actions.js (named action table)
│ data-state-* display themselves │ render.fragment
▼ ▼
DOM ◀── rescan after insert ── renderBlade.js ── chosen params ──▶ function from render::register
◀──── HTML fragment ────| System | Single responsibility | Doesn't |
|---|---|---|
| Linker | Business round trips: a call goes in, data + pipeline come out | Return HTML or touch the DOM |
| Render fragments | Transport HTML | Make business decisions |
| state | Client memory + declarative display | Send requests |
When Linker wants to replace a block of HTML, it returns an Action::render_fragment(...) asking render fragments to do it. Linker never produces HTML itself.
Four sentences
- State doesn't live in the DOM. The DOM is just a display; replacing the display doesn't touch the content.
- The name is the namespace. Two render objects with different names have completely separate state, so the same template can appear twice.
- Declarative attributes only display and record. To compute something, have the server return a value, or write your own JS action.
- State doesn't leave the browser. To tell the server, pick the values yourself and put them in
paramsor Linker arguments, and the server validates them again.
Two kinds of "state": don't mix them up
| Client state | Linker server state (Stateful) | |
|---|---|---|
| Where it lives | The tab's JS memory | The server cache (linker:{user}:{uuid}); the browser only has the uuid |
| What it looks like | Key-value | Your component struct, stored with serde |
| Who can change it | The user (DevTools included) | Only Rust |
| Good for | Tabs, expand/collapse, filters, unsaved input | Which wizard step you're on, business data kept across calls |
| Never put here | Permissions, amounts, anything that must be trusted | Data that must survive a reload (use the DB) |
| Survives a reload? | No | No |
The test: "If the user changes this value in DevTools, what's the worst that can happen?" If the answer is "the page looks odd", keep it on the client. If it's "they get something they shouldn't", keep it on the server or in the DB.
Who do I call?
| I want to… | Use |
|---|---|
| Switch tabs, expand/collapse, show/hide | data-state-* (no server needed) |
| Redraw a block of HTML | Render fragments (runtime::render_trigger / render_auto, or Linker returns Action::render_fragment) |
| Save data, validate, check duplicates, compute amounts | LinkerComponent::call |
| A list with the same structure, only the data changes | Linker returns dom.repeat |
| Content that depends on who's logged in | Linker (it has context.user); fragment functions can't see the user |
| SEO, works without JS | A normal route + form |
Attributes are the only entry point
The framework attaches nothing to window. A page can only do things through HTML attributes, and those are generated in Rust:
runtime::render_object("name", &[Allow::…]): what this block of DOM is allowed to do (Render/StateRead/StateWrite)linker::mount::<C, User>(&user, params): which Linker component this block of DOM belongs to
These are two separate things, and you need both. A Linker mount that uses data-state-text still needs a render object granting StateRead. The example project puts both sets of attributes on the same element:
let attrs = mount.html()
+ &runtime::render_object("counter", &[Allow::Render, Allow::StateRead, Allow::StateWrite]).render(&[]);The shape on the Rust side
| You write | Where | Registered in |
|---|---|---|
Fragment functions async fn(RenderInput) -> Result<Html> | src/cg/*.rs | register() in src/cg/mod.rs |
LinkerComponent structs | src/cg/*.rs | Same |
Page handlers (mount, build attributes, view(...)) | src/http/handlers/ | src/routes/web.rs |
| Templates | resources/views/ | — |
register() is called once at the start of configure() in src/app.rs. The registry is the allow list: an unregistered fragment name gets 422, an unregistered Linker alias gets 404.
Next, read Render fragments, or jump straight to Linker.