Add simple yew frontend

This commit is contained in:
Marko Korhonen 2020-04-13 17:48:42 +03:00
parent a0e8cfe5f9
commit bbaf01dafe
No known key found for this signature in database
GPG key ID: 911B85FBC6003FE5
26 changed files with 711 additions and 31 deletions

View file

@ -0,0 +1,47 @@
use yew::prelude::*;
struct App {
clicked: bool,
onclick: Callback<ClickEvent>,
}
enum Msg {
Click,
}
impl Component for App {
type Message = Msg;
type Properties = ();
fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self {
App {
clicked: false,
onclick: link.callback(|_| Msg::Click),
}
}
fn update(&mut self, msg: Self::Message) -> ShouldRender {
match msg {
Msg::Click => {
if self.clicked {
self.clicked = false;
} else {
self.clicked = true
}
true
}
}
}
fn view(&self) -> Html {
let button_text = if self.clicked { "Clicked!" } else { "Click me" };
html! {
<button onclick=&self.onclick>{ button_text }</button>
}
}
}
fn main() {
yew::start_app::<App>();
}