Skip to content

Instantly share code, notes, and snippets.

@davidpdrsn
Created August 7, 2020 10:21
Show Gist options
  • Save davidpdrsn/458f32e9983f08e53fdd0db7c888d650 to your computer and use it in GitHub Desktop.
Save davidpdrsn/458f32e9983f08e53fdd0db7c888d650 to your computer and use it in GitHub Desktop.
Seed app
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