-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "webapp" | ||
version = "0.1.0" | ||
authors = ["colder <colder@vitarn.com>"] | ||
edition = "2018" | ||
publish = false | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[dependencies] | ||
yew = { version = "0.17.2", features = ["web_sys"] } | ||
wasm-bindgen = "0.2.67" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use wasm_bindgen::prelude::*; | ||
use yew::prelude::*; | ||
|
||
struct Model { | ||
link: ComponentLink<Self>, | ||
value: i64, | ||
} | ||
|
||
enum Msg { | ||
AddOne, | ||
} | ||
|
||
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(); | ||
} |