Skip to content

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 ​

SystemSingle responsibilityDoes not
LinkerBusiness round-trips: call in, data + pipeline outReturn HTML or touch the DOM
renderBladeHTML transportDecide business logic
stateClient memory + declarative renderingSend 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 ​

  1. State doesn't live in the DOM. The DOM is just a display; replacing the display doesn't change the content.
  2. The name is the namespace. Two @renderObjects with different names have fully isolated state, so the same template can appear twice.
  3. Declarative attributes only display and record. "Computing" belongs in a CGEvent or comes back from the server.
  4. State never leaves the browser. If the server needs to know, pick the values into params yourself, and the server validates them again.

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

Client stateLinker server state (Stateful)
Lives inThe tab's JS memoryServer cache; the browser only has a uuid
Who can change itThe user (DevTools included)Only PHP
Good forTabs, expanded rows, filters, unsaved inputWhich wizard step you're on, business data between calls
Never put herePermissions, amounts, anything that must be trustedData that must survive a reload (use the database)
Survives reload?NoNo

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/hidedata-state-* (no server needed)
Re-render a list or a detail blockrenderBlade (data-cg-event="renderBlade", or Linker returning render.fragment)
Save, validate, check duplicates, compute pricesA Linker #[Computable] method
A list with identical rows, only data changesLinker returning dom.repeat
Upload file bytesFileDrop (then send the file id through Linker)
SEO, no-JS supportOrdinary 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.