use fission::prelude::*;
#[fission_component]
struct CounterApp {
#[local_state(default = 0)]
count: i32,
}
#[fission_reducer(Increment)]
fn increment(count: &mut i32) {
*count += 1;
}
impl From<CounterApp> for Widget {
fn from(counter: CounterApp) -> Widget {
let (ctx, _) = fission::build::current::<()>();
let count = counter.count();
let increment = ctx.bind_local(Increment, count.clone(), reduce!(increment));
Container::new(Column {
gap: Some(20.0),
children: widgets![
Text::new("Counter").size(32.0),
Text::new(format!("{}", count.get())).size(56.0),
Button {
on_press: Some(increment),
child: Some(Text::new("Increment").into()),
..Default::default()
},
],
..Default::default()
})
.padding_all(32.0)
.into()
}
}
fn main() -> anyhow::Result<()> {
DesktopApp::<(), _>::new(CounterApp {}).run()
}
Check | Expected result |
|---|---|
Build | cargo check or the relevant fission command finishes without target-specific configuration errors. |
Behavior | The screen, package, server route, or test flow described by the recipe is visible and responds to input. |
Failure path | At least one denied, missing, invalid, or empty case renders a useful message instead of silently doing nothing. |
Next link | The reference page linked from the recipe explains the exact fields, commands, or types used here. |