Created
August 7, 2020 10:21
-
-
Save davidpdrsn/458f32e9983f08e53fdd0db7c888d650 to your computer and use it in GitHub Desktop.
Seed app
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
use seed::{prelude::*, *}; | |
pub struct Model { | |
url: Url, | |
} | |
pub enum Msg { | |
UrlChanged(Url), | |
} | |
fn update(msg: Msg, model: &mut Model, _: &mut impl Orders<Msg>) { | |
match msg { | |
Msg::UrlChanged(url) => { | |
log!("update", url.to_string()); | |
model.url = url; | |
} | |
} | |
} | |
fn view(model: &Model) -> Node<Msg> { | |
div![ | |
p![ | |
a!["Root", attrs! { At::Href => "/" }], | |
" | ", | |
a!["Page one", attrs! { At::Href => "/page_one" }], | |
" | ", | |
a!["Page two", attrs! { At::Href => "/page_two" }], | |
" | ", | |
a!["Page three", attrs! { At::Href => "/page_three" }], | |
], | |
p!["URL in model: ", code![model.url.to_string()]], | |
] | |
} | |
fn after_mount(url: Url, _: &mut impl Orders<Msg>) -> AfterMount<Model> { | |
log!("after mount", url.to_string()); | |
AfterMount::new(Model { | |
url: url.to_base_url(), | |
}) | |
} | |
fn routes(url: Url) -> Option<Msg> { | |
log!("routes", url.to_string()); | |
Some(Msg::UrlChanged(url)) | |
} | |
#[wasm_bindgen(start)] | |
pub fn start() { | |
App::builder(update, view) | |
.after_mount(after_mount) | |
.routes(routes) | |
.build_and_start(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment