Skip to content

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 ────
SystemSingle responsibilityDoesn't
LinkerBusiness round trips: a call goes in, data + pipeline come outReturn HTML or touch the DOM
Render fragmentsTransport HTMLMake business decisions
stateClient memory + declarative displaySend 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 ​

  1. State doesn't live in the DOM. The DOM is just a display; replacing the display doesn't touch the content.
  2. The name is the namespace. Two render objects with different names have completely separate state, so the same template can appear twice.
  3. Declarative attributes only display and record. To compute something, have the server return a value, or write your own JS action.
  4. State doesn't leave the browser. To tell the server, pick the values yourself and put them in params or Linker arguments, and the server validates them again.

Two kinds of "state": don't mix them up ​

Client stateLinker server state (Stateful)
Where it livesThe tab's JS memoryThe server cache (linker:{user}:{uuid}); the browser only has the uuid
What it looks likeKey-valueYour component struct, stored with serde
Who can change itThe user (DevTools included)Only Rust
Good forTabs, expand/collapse, filters, unsaved inputWhich wizard step you're on, business data kept across calls
Never put herePermissions, amounts, anything that must be trustedData that must survive a reload (use the DB)
Survives a reload?NoNo

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/hidedata-state-* (no server needed)
Redraw a block of HTMLRender fragments (runtime::render_trigger / render_auto, or Linker returns Action::render_fragment)
Save data, validate, check duplicates, compute amountsLinkerComponent::call
A list with the same structure, only the data changesLinker returns dom.repeat
Content that depends on who's logged inLinker (it has context.user); fragment functions can't see the user
SEO, works without JSA 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:

rust
let attrs = mount.html()
    + &runtime::render_object("counter", &[Allow::Render, Allow::StateRead, Allow::StateWrite]).render(&[]);

The shape on the Rust side ​

You writeWhereRegistered in
Fragment functions async fn(RenderInput) -> Result<Html>src/cg/*.rsregister() in src/cg/mod.rs
LinkerComponent structssrc/cg/*.rsSame
Page handlers (mount, build attributes, view(...))src/http/handlers/src/routes/web.rs
Templatesresources/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.