Created
April 12, 2022 14:56
-
-
Save ivanceras/401bc1876b21b1f98519c8137bf36e40 to your computer and use it in GitHub Desktop.
Application trait
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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