diff options
author | jelemux <jeremias.weber@protonmail.com> | 2020-10-18 22:40:57 +0200 |
---|---|---|
committer | jelemux <jeremias.weber@protonmail.com> | 2020-10-18 22:40:57 +0200 |
commit | 84c2dab4200c37c818d83c95f85445ee00d83bf6 (patch) | |
tree | 134d9ec538306a6626d35e737035e03c8b3a69c5 /src/view.rs | |
download | wasm-card-84c2dab4200c37c818d83c95f85445ee00d83bf6.tar.gz wasm-card-84c2dab4200c37c818d83c95f85445ee00d83bf6.tar.bz2 |
initial commit
Diffstat (limited to 'src/view.rs')
-rw-r--r-- | src/view.rs | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/view.rs b/src/view.rs new file mode 100644 index 0000000..81634ed --- /dev/null +++ b/src/view.rs @@ -0,0 +1,83 @@ +use crate::model::BCard; +use wasm_bindgen::prelude::*; +use yew::prelude::*; + +struct Form { + link: ComponentLink<Self>, + bcard: BCard, +} + +impl Component for Form { // probably not necessary but who knows + type Message = (); + type Properties = (); + + fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self { + Self { link } + } + + fn update(&mut self, _: Self::Message) -> ShouldRender { + false + } + + fn change(&mut self, _: Self::Properties) -> ShouldRender { + false + } + + fn view(&self) -> Html { + html! { + <BCardForm/> + } + } +} + +// example + +struct Model { + link: ComponentLink<Self>, + value: i64, +} + +enum Msg { + AddOne, + Input(BCard), +} + +impl Component for Model { + type Message = Msg; + type Properties = (); + + fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self { + Self { + link, + value: 0, + } + } + + fn update(&mut self, msg: Self::Message) -> ShouldRender { + match msg { + Msg::AddOne => self.value += 1 + } + true + } + + fn change(&mut self, _props: Self::Properties) -> ShouldRender { + // Should only return "true" if new properties are different to + // previously received properties. + // This component has no properties so we will always return "false". + false + } + + fn view(&self) -> Html { + html! { + <div> + <button onclick=self.link.callback(|_| Msg::AddOne)>{ "+1" }</button> + <p>{ self.value }</p> + </div> + } + } +} + +#[wasm_bindgen(start)] +pub fn run_app() { + App::<Model>::new().mount_to_body(); +}
\ No newline at end of file |