events

package
v0.2.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package events is the compiled source for docs/guide/events-and-forms.md.

It is a composer: a form that submits, a field that reports every keystroke, a checkbox whose absence means something, and a key that clears the draft.

templ: version: v0.3.1020

Index

Constants

View Source
const (
	EventSubmit = "compose.submit"
	EventDraft  = "compose.draft"
	EventClear  = "compose.clear"
)

The event names. Every one of them is in Config.Events; a name that is not there is refused with UNKNOWN_EVENT and counted, and never reaches Reduce.

View Source
const (
	FieldBody   = "body"
	FieldUrgent = "urgent"
)

The form field names. They are the name attributes in view.templ and the keys Fields is read with, so they are constants rather than two spellings of one string.

View Source
const MaxBody = 140

MaxBody is the length the reducer enforces. The client enforces nothing: validation is state the server computes, and the browser is not asked to agree.

Variables

This section is empty.

Functions

func ComposerRegion

func ComposerRegion(s State) templ.Component

ComposerRegion is the whole vocabulary in one fragment.

The form's submit binding sends every field the form contains. The input's own binding sends that one control, debounced. The key binding clears the draft and fires for no key but Escape. All three go through one client listener and one server event path.

The two bindings on the input are composed with live.OnAll and only one of them is debounced. That is the whole of it now, and it is worth one sentence because it was not always so: until 2026-08-05 Debounce was an attribute of the element, so the Escape binding inherited the input's 150 ms and a keystroke inside that window destroyed the pending clear outright. This component is the page that defect was found on.

aria-invalid and aria-describedby are written by hand, deliberately: they are markup decisions belonging to this application's design system, and the library ships no form vocabulary that would own them.

Types

type State

type State struct {
	Draft      string
	DraftError string
	Posted     int
	LastBody   string
	LastUrgent bool
}

State is one session's view of the composer.

Every field is comparable, which is a requirement rather than a preference — see guide/fragments-and-dirty-tracking.md.

func Reduce

func Reduce(s State, ev live.Event) (State, []live.Effect[live.AnonymousIdentity])

Reduce is the pure state transition.

func (State) Remaining

func (s State) Remaining() int

Remaining is derived state the fragment renders. It is a method rather than a template expression so the fragment's Dirty function can compare exactly what the markup shows.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL