pub const BUTTON: &str = "type Button { label: Str = \"Button\"; action: func() -> Res[Unit, DataError] = noop; }";Expand description
A host-rendered control with a typed no-argument action.
The host invokes action through Machine::invoke_component. The default noop
is intentional; a Button schema never dispatches an action by itself.
§Declaration
type Button { label: Str = "Button"; action: func() -> Res[Unit, DataError] = noop; }§Fields and methods
-
label: Visible label; defaults to Button. -
action: Typed zero-argument callback; defaults to noop. Bind a live component method to persist mutations.
§Use the default action
The default callback is callable and produces no log output.
let button = Button {};
button.action()?;
print(button.label);§Expose a clickable control
The spawned control retains a typed callback for host click dispatch; initialization makes the example’s ready state observable.
func activate() -> Res[Unit, DataError] { print("activated"); ret Ok(()); }
let control = spawn(Button { label: "Start", action: activate });
print("button ready");