Action primitives
Contract
v0.1.22 adds Go action primitives for recurring click, change, and submit
flows. An action is a typed Go function with visible state: idle, running,
success, validation error, provider error, or canceled. Components can render
that state through ordinary GX nodes and request updates through the state
runtime.
save := uiaction.Action[Draft]{
Name: "save-draft",
Run: func(ctx context.Context, draft Draft) uiaction.Result {
return client.Save(ctx, draft)
},
}
func SaveButton(draft Draft) gx.Node {
state := uiaction.UseAction(save)
return <button onClick={state.Run(draft)} disabled={state.Running()}>
<Text value={state.Label("Save")}></Text>
</button>
}
Actions centralize dispatch, pending state, result projection, redacted failure logging, and test fakes. They can be called from server-rendered markup, mounted WASM views, and pure unit tests without embedding JavaScript clients.
Requirements
- Actions are typed Go values, not string event registries.
-
RunActionexposes context cancellation and deterministic result state. - Busy, success, validation-error, provider-error, and canceled states are visible to renderers.
- Tests can fake action results without a browser or provider.
- Native form events use the helpers from v0.1.19.
Boundary
This patch does not define HTTP resources, session storage, redirects, upload policy, or provider-specific errors. Actions describe local dispatch and result state; resource and session primitives provide the host-facing pieces later.