Skip to content

Instantly share code, notes, and snippets.

@o0Ignition0o
Created November 4, 2018 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save o0Ignition0o/e8b467607046fe220e31e167187d98fa to your computer and use it in GitHub Desktop.
Save o0Ignition0o/e8b467607046fe220e31e167187d98fa to your computer and use it in GitHub Desktop.
yew rust framework: mount component to dom macro
pub enum MountError {
QuerySelectorError,
ElementNotFound(String)
}
impl From<TODO> for MountError {
fn from(_: TODO) -> Self {
MountError::QuerySelectorError
}
}
macro_rules! mount {
($element:expr, $model:ty) => {{
|()| -> Result<(),MountError> {
if let Some(element) = document().query_selector($element)? {
App::<$model>::new().mount(element);
Ok(())
} else {
Err(MountError::ElementNotFound(format!("Could not find the element {} in the DOM.", $element)))
}
}
}};
}
pub fn mount_app() -> () {
mount!("#banner", Banner);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment