Mental Model
After this page you should be able to answer: "Where does this value belong? Who should do this job?"
Three roles, no overlap
| System | Single responsibility | Does not |
|---|---|---|
| Linker | Business round-trips: call in, data + pipeline out | Return HTML or touch the DOM |
| renderBlade | HTML transport | Decide business logic |
| state | Client memory + declarative rendering | Send requests |
When Linker wants a block of HTML replaced, it returns a render.fragment action asking renderBlade to do it. It never produces HTML itself.
Four sentences
- State doesn't live in the DOM. The DOM is just a display; replacing the display doesn't change the content.
- The name is the namespace. Two
@renderObjects with different names have fully isolated state, so the same template can appear twice. - Declarative attributes only display and record. "Computing" belongs in a CGEvent or comes back from the server.
- State never leaves the browser. If the server needs to know, pick the values into
paramsyourself, and the server validates them again.
Two kinds of "state": don't mix them up
| Client state | Linker server state (Stateful) | |
|---|---|---|
| Lives in | The tab's JS memory | Server cache; the browser only has a uuid |
| Who can change it | The user (DevTools included) | Only PHP |
| Good for | Tabs, expanded rows, filters, unsaved input | Which wizard step you're on, business data between calls |
| Never put here | Permissions, amounts, anything that must be trusted | Data that must survive a reload (use the database) |
| Survives reload? | No | No |
The test: "If the user changes this value in DevTools, what's the worst that happens?" If the answer is "the screen looks odd", it can be client state. If the answer is "they get something they shouldn't", keep it on the server or in the database.
Who should do it?
| I want to… | Use |
|---|---|
| Switch tabs, expand/collapse, show/hide | data-state-* (no server needed) |
| Re-render a list or a detail block | renderBlade (data-cg-event="renderBlade", or Linker returning render.fragment) |
| Save, validate, check duplicates, compute prices | A Linker #[Computable] method |
| A list with identical rows, only data changes | Linker returning dom.repeat |
| Upload file bytes | FileDrop (then send the file id through Linker) |
| SEO, no-JS support | Ordinary routes + form POST |
Attributes are the only entry point
The framework hangs nothing on window. A page can only make things happen through HTML attributes:
@renderObject('name', [allow list]): what this block of DOM may do (render/state:read/state:write)@linker('alias'): which Linker component this block belongs to
These are two different things, and you need both. If a block has @linker but uses data-state-bind, it still needs an @renderObject that grants state:write.
Next: read renderBlade, or jump to Linker.