Triggers & Listeners
"The user did something → which method is called → who can hear about it afterwards."
Trigger events
| Element | Default event |
|---|---|
| Buttons, links, etc. | click |
input / select / textarea | change |
Change it with data-linker-on:
<input name="keyword" data-linker-call="search" data-linker-on="input" data-linker-debounce="400" data-linker-args="keyword">
{{-- Several moments calling the same method --}}
<input name="qty" data-linker-call="quote" data-linker-on="change,blur" data-linker-args="qty">
{{-- Form submit --}}
<form data-linker-call="save" data-linker-on="submit" data-linker-args="form">…</form>prevent (blocking the default behavior) only defaults on for click and submit. Bound to submit, it blocks the browser's native submit, so nothing is sent twice.
One element, different moments, different methods: @linkerBind
<input name="email" @linkerBind([
['on' => 'input', 'call' => 'checkEmail', 'debounce' => 300, 'args' => 'email'],
['on' => 'blur', 'call' => 'saveDraft', 'args' => 'form'],
])>| Rule | Behavior |
|---|---|
| Later cancels earlier | A new trigger clears pending debounces on the same element (when blur fires, an unsent input is dropped) |
| Timers are per binding | Stored on the element; two buttons calling the same method don't cancel each other |
| Typos | Event names, method names, debounce types, unknown keys and duplicate "same event, same method" throw when Blade renders |
Debouncing and double-click protection
| Mechanism | Scope | Behavior |
|---|---|---|
data-linker-debounce="400" | Element | Sends 400 ms after input stops |
Minimum interaction interval (LINKER_MIN_DELAY_SECONDS, default 0.8 s) | Element | Buttons start disabled after mounting until the interval passes; after sending, locked until "the work is done and the interval has passed" |
| Busy during a request | Element | Disabled during the request, restored afterwards |
While locked: button triggers are dropped; input fields keep only the latest value and send it when unlocked. Otherwise the server would never learn what the user finally chose.
Confirm before sending
<button data-linker-call="archive"
data-linker-args='{"id": 7}'
data-linker-confirm="Archived items no longer appear in the list"
data-linker-confirm-title="Archive"
data-linker-confirm-label="Archive">Archive</button>Add data-linker-confirm-danger for the danger style and a required second click. The server can also ask from inside the pipeline (ui.confirm); see Execution Order.
Re-fetch on reconnect
<button data-linker-call="show" data-linker-args='{"page":1}' data-linker-refresh-on-reconnect>Refresh</button>For reads only. Writes are never resent automatically (the failed attempt may have been saved). Arguments must be a JSON object; elements with data-linker-confirm are skipped even if marked.
FileDrop and other guards
Before sending data-linker-args="form", Linker dispatches a cancelable submit event on the form. Components like FileDrop cancel it while an upload is unfinished, and Linker then silently doesn't send. So don't put onsubmit="return false" on the form.
Listening: who hears about a call afterwards
The framework attaches no API to window. It only dispatches DOM events:
| Event | When | detail |
|---|---|---|
cg:state | Every client state write (including data returned by Linker) | { key, value, previous } |
cg:rendered | After a renderBlade fragment is inserted, or dom.repeat inserts rows | { root, … } |
cg:error | Exceptions in rendering or subscribers | Exception info |
// In your own CGEvent, or while debugging
document.addEventListener('cg:state', (e) => {
if (e.detail.key === 'orderPanel:total') {
console.log('total', e.detail.previous, '→', e.detail.value);
}
});
document.addEventListener('cg:rendered', (e) => {
// when a third-party library must initialize on new nodes
e.detail.root.querySelectorAll('[data-tooltip]').forEach(initTooltip);
});Declarative listening is simply data-state-*: when a value changes, the binding re-renders on its own, with no listener to write.
Chained actions: one call, several steps
The server returns several actions that run in order:
return $this->ok(['saved' => true])
->call('ui.toast', ['level' => 'success', 'message' => 'Saved'])
->then('state.clear', ['scope' => 'orderForm'])
->then('render.fragment', ['target' => '#orders', 'name' => OrderController::class, 'fresh' => true])
->then('dom.scrollTo', ['target' => '#orders']);No Promise chaining on the front end. The rules are in Execution Order.