ket/
lib.rs

1use wasm_bindgen::prelude::*;
2use yew::prelude::*;
3
4struct Model {
5    link: ComponentLink<Self>,
6    value: i64,
7}
8
9enum Msg {
10    AddOne,
11}
12
13impl Component for Model {
14    type Message = Msg;
15    type Properties = ();
16    fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self {
17        Self {
18            link,
19            value: 0,
20        }
21    }
22
23    fn update(&mut self, msg: Self::Message) -> ShouldRender {
24        match msg {
25            Msg::AddOne => self.value += 1
26        }
27        true
28    }
29
30    fn change(&mut self, _props: Self::Properties) -> ShouldRender {
31        // Should only return "true" if new properties are different to
32        // previously received properties.
33        // This component has no properties so we will always return "false".
34        false
35    }
36
37    fn view(&self) -> Html {
38        html! {
39            <div>
40                <button onclick=self.link.callback(|_| Msg::AddOne)>{ "+1" }</button>
41                <p>{ self.value }</p>
42            </div>
43        }
44    }
45}
46
47#[wasm_bindgen(start)]
48pub fn run_app() {
49    App::<Model>::new().mount_to_body();
50}