Skip to content
Brew

Brew actions

An action is a public method on your component. The browser invokes it with wire:click, other wire:* events, wire:submit, or $wire.method() from Alpine.

<button wire:click="increment">+</button>
<button wire:click="add(5)">+5</button>
<button wire:click="save('draft', true)">Save</button>

Parameters are JSON-encoded and passed positionally. Trailing parameters can be resolved from the Kona container (dependency injection).

fun increment() { count++ }
fun add(amount: Int) { count += amount }
fun save(label: String, notify: Boolean) { /* … */ }

Return a value and read it from JavaScript:

fun doubled(): Int = count * 2
<button x-data x-on:click="alert(await $wire.doubled())">Doubled?</button>

Returns travel in effects.returns.

Skip the HTML re-render when you only need to mutate state or return a value:

@Renderless
fun clearQuietly() {
count = 0
}

Or call skipRender() / renderless() inside the method. forceRender() makes later skip calls no-ops for that request. The .renderless event modifier does the same from the template.

Call Effect
$set('count', 1) Set a property
$toggle('open') Flip a boolean
$refresh Re-render without a named method
$event Access the DOM event from Alpine
<button wire:click="$set('count', 0)">Reset</button>
<button wire:click="$toggle('open')">Toggle</button>
<button wire:click="$refresh">Refresh</button>

wire:<event> works for native and custom events:

<input wire:keydown.enter="search" />
<div wire:click.outside="close"></div>
<input wire:trix-change="updated" />

.enter, .escape, .space, .tab, .shift, .ctrl, .alt, .meta / .cmd, .up / .down / .left / .right, .page-up / .page-down, .slash, and combinations like .shift.enter.

.prevent, .stop, .window, .document, .outside, .once, .self, .camel, .dot, .passive, .capture, .debounce / .debounce.500ms, .throttle / .throttle.500ms.

<form wire:submit="save">
<input wire:model="email" />
<button type="submit">Save</button>
</form>

wire:submit implies .prevent. See Forms for wire:model modifiers.

await $wire.save()
await $wire.$call('add', 5)
await $wire.$refresh()
await $wire.$commit()

$wire also exposes $el, $id, $watch, and $hook.

Interactions queue per component. Live wire:model updates coalesce; actions interrupt or queue according to Brew’s request bus so rapid clicks do not race the morph.

Protected/private methods, render / template, and lifecycle hooks (mount, boot, updatedFoo, …) are not browser-callable. Attempts raise method-not-found or lifecycle-guard errors.

  • Forms — model binding details
  • JavaScript — global Brew API and hooks
  • Lifecycle — hooks around actions and updates