Skip to content

Instantly share code, notes, and snippets.

@ivanceras
Created April 12, 2022 14:56
Show Gist options
  • Save ivanceras/401bc1876b21b1f98519c8137bf36e40 to your computer and use it in GitHub Desktop.
Save ivanceras/401bc1876b21b1f98519c8137bf36e40 to your computer and use it in GitHub Desktop.
Application trait
impl Application<Msg> for App {
fn view(&self) -> Node<Msg> {
node! {
<main>
<input type="button"
value="+"
on_click=|_| {
Msg::Increment
}
/>
<button class="count" on_click=|_|{Msg::Reset} >{text(self.count)}</button>
<input type="button"
value="-"
on_click=|_| {
Msg::Decrement
}
/>
</main>
}
}
fn update(&mut self, msg: Msg) -> Cmd<Self, Msg> {
match msg {
Msg::Increment => self.count += 1,
Msg::Decrement => self.count -= 1,
Msg::Reset => self.count = 0,
}
Cmd::none()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment