diff options
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 |