Skip to content

Triggers & Listeners ​

"The user did something → which method is called → who can hear about it afterwards."

Trigger events ​

ElementDefault event
Buttons, links, etc.click
input / select / textareachange

Change it with data-linker-on:

blade
<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 ​

blade
<input name="email" @linkerBind([
    ['on' => 'input', 'call' => 'checkEmail', 'debounce' => 300, 'args' => 'email'],
    ['on' => 'blur',  'call' => 'saveDraft',  'args' => 'form'],
])>
RuleBehavior
Later cancels earlierA new trigger clears pending debounces on the same element (when blur fires, an unsent input is dropped)
Timers are per bindingStored on the element; two buttons calling the same method don't cancel each other
TyposEvent names, method names, debounce types, unknown keys and duplicate "same event, same method" throw when Blade renders

Debouncing and double-click protection ​

MechanismScopeBehavior
data-linker-debounce="400"ElementSends 400 ms after input stops
Minimum interaction interval (LINKER_MIN_DELAY_SECONDS, default 0.8 s)ElementButtons start disabled after mounting until the interval passes; after sending, locked until "the work is done and the interval has passed"
Busy during a requestElementDisabled 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 ​

blade
<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 ​

blade
<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:

EventWhendetail
cg:stateEvery client state write (including data returned by Linker){ key, value, previous }
cg:renderedAfter a renderBlade fragment is inserted, or dom.repeat inserts rows{ root, … }
cg:errorExceptions in rendering or subscribersException info
js
// 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:

php
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.