pub type ClosureProp = Box<dyn FnMut()>;Expand description
A type commonly used for construction of a wasm-bindgen Closure for use with DOM Element Event Handlers.
§Examples
In this example &self is a tuple struct which implements rust_fel::Component
ⓘ
fn render(&self) -> rust_fel::Element {
let borrow = self.0.borrow_mut();
let state = borrow.state.clone();
let mut new_clone = self.clone();
let (theme_onclick, theme_class) = match state.action {
Actions::LightMode => (
Box::new(move || new_clone.reduce_state(Actions::LightMode))
as rust_fel::ClosureProp,
"Light-Mode".to_owned(),
),
Actions::DarkMode => (
Box::new(move || new_clone.reduce_state(Actions::DarkMode))
as rust_fel::ClosureProp,
"Dark-Mode".to_owned(),
),
_ => (Box::new(|| ()) as rust_fel::ClosureProp, "".to_owned()),
};
rust_fel::Element::new(
"main".to_owned(),
rust_fel::Props {
id: Some(borrow.id.clone()),
onclick: Some(theme_onclick),
class_name: Some(format!("main {}", theme_class)),
..Default::default()
},
)
}Aliased Type§
pub struct ClosureProp(/* private fields */);