FlowView Events
Native events in your template, no listener boilerplate
Events is a separate, optional compiler. Write (event)="handler()" next to the markup, declare handlers in one<script data-flowview> block, and FlowView wires up delegated native listeners. It works in Astro (@flowview/astro-events) and plain Vite projects such as Hono (@flowview/vite-events).
Live, from this page
Compiled by FlowView EventsClick an action to see the compiled event handlers run.
---
---
<button (click)="save($event)">Save</button>
<button (click)="removeItem('item-1', $el)">
Remove
</button>
<script data-flowview>
function save(event) {
const output = document.querySelector("#event-output");
output.textContent = `Saved from a ${event.type} event`;
}
function removeItem(id, element) {
element.setAttribute("disabled", "true");
}
</script><button
data-flow-on-click="save"
data-flow-scope="a1b2c3d4e5f6"
data-flow-args='[{"__flow":"$event"}]'
>
Save
</button>
<script>
function save(event) {
const output = document.querySelector("#event-output");
output.textContent = `Saved from a ${event.type} event`;
}
function removeItem(id, element) {
element.setAttribute("disabled", "true");
}
import { registerFlowHandlers } from "@flowview/events/runtime";
registerFlowHandlers("a1b2c3d4e5f6", { removeItem, save }, ["click"]);
</script>What a handler can receive
$event- The native browser event.
$el- The element the binding is on.
- Literal arguments
- Strings, numbers and booleans, such as
remove('item-1'), serialized into the markup. - Template-scope property paths
- Values such as
item.idinside an@forloop are read at render time. - Build-time validation
- Every binding must resolve to a function declared in the file's single script block.
<button (click)="save()">Save</button>
<input (input)="search($event)" />
<select (change)="change($event)">
<option value="a">A</option>
<option value="b">B</option>
</select>
<form (submit)="submit($event)">
<button>Send</button>
</form>
<button (click)="remove('item-1', $el)">Remove</button>
<script data-flowview>
function save() {}
function search(event) { /* event.target.value */ }
function change(event) {}
function submit(event) { event.preventDefault(); }
function remove(id, element) {}
</script>Native forms and explicit replacement
Events passes native input,change,submit, keyboard, focus/blur, composition and details toggle events to the handler. The handler ownspreventDefault() and any state commit. Boolean bindings such as [checked]serialize HTML attributes; they do not track later live control properties. An explicit view.update()replaces controls and does not promise to preserve dirty values, focus, selection or IME composition. See the form examples and tested limits in the repository README.
Delegated listeners and dynamic DOM
The runtime attaches one listener per event type to the document and finds the handler when the event fires. Elements added later, such as a re-rendered @for list or a view replaced by @flowview/dom, work with no rebinding.See it on the client DOM page →
Scopes and navigation
Each template file gets its own handler scope, so two components can both declare save() without colliding. In Astro, handlers keep working across View Transitions navigation. Both behaviors are asserted in the browser suite listed onthe capabilities page.
Events and the HTML compiler are separate
The Events compiler runs first and rewrites (click) into data-flow-on-click attributes. The Rust HTML compiler never parses event syntax, which keeps the core small and means FlowView templates remain usable without any browser code at all.
Install: @flowview/astro-events for Astro,@flowview/vite-events for Vite, both on top of@flowview/events. Setup steps →