pub enum RespoNode<T>where
T: Debug + Clone,{
Component(String, Vec<RespoEffect>, Box<RespoNode<T>>),
Element {
name: String,
attrs: HashMap<String, String>,
event: HashMap<String, RespoListenerFn<T>>,
style: RespoStyle,
children: Vec<(RespoIndexKey, RespoNode<T>)>,
},
Referenced(Rc<RespoNode<T>>),
}
Expand description
an Element
or a Component
Variants§
Component(String, Vec<RespoEffect>, Box<RespoNode<T>>)
Element
Fields
event: HashMap<String, RespoListenerFn<T>>
style: RespoStyle
inlines styles, partially typed.
there’s also a macro called static_styles
for inserting CSS rules
children: Vec<(RespoIndexKey, RespoNode<T>)>
each child as a key like a string, by default generated from index, they are used in diffing, so it’s better to be distinct, although not required to be.
corresponding to DOM elements
Referenced(Rc<RespoNode<T>>)
Implementations§
source§impl<T> RespoNode<T>where
T: Debug + Clone,
impl<T> RespoNode<T>where
T: Debug + Clone,
sourcepub fn new_component(name: &str, tree: RespoNode<T>) -> Self
pub fn new_component(name: &str, tree: RespoNode<T>) -> Self
create a new component
sourcepub fn style(&mut self, more: RespoStyle) -> &mut Self
pub fn style(&mut self, more: RespoStyle) -> &mut Self
attach styles
element.style(RespoStyle::default().margin(10))
sourcepub fn modify_style<U>(&mut self, builder: U) -> &mut Selfwhere
U: Fn(&mut RespoStyle),
pub fn modify_style<U>(&mut self, builder: U) -> &mut Selfwhere
U: Fn(&mut RespoStyle),
imparative way of updating style
element.modify_style(|s| {
if data > 1 {
s.color(CssColor::Red);
}
});
sourcepub fn attribute<U, V>(&mut self, property: U, value: V) -> &mut Selfwhere
U: Into<String> + ToOwned,
V: Display,
pub fn attribute<U, V>(&mut self, property: U, value: V) -> &mut Selfwhere
U: Into<String> + ToOwned,
V: Display,
set an attribute on element
sourcepub fn maybe_attribute<U, V>(
&mut self,
property: U,
value: Option<V>
) -> &mut Selfwhere
U: Into<String> + ToOwned,
V: Display,
pub fn maybe_attribute<U, V>(
&mut self,
property: U,
value: Option<V>
) -> &mut Selfwhere
U: Into<String> + ToOwned,
V: Display,
set an attribute on element, but using None
indicates noting
pub fn on_click<U>(&mut self, handler: U) -> &mut Selfwhere
U: Fn(RespoEvent, DispatchFn<T>) -> Result<(), String> + 'static,
pub fn on_input<U>(&mut self, handler: U) -> &mut Selfwhere
U: Fn(RespoEvent, DispatchFn<T>) -> Result<(), String> + 'static,
sourcepub fn on_keydown<U>(&mut self, handler: U) -> &mut Selfwhere
U: Fn(RespoEvent, DispatchFn<T>) -> Result<(), String> + 'static,
pub fn on_keydown<U>(&mut self, handler: U) -> &mut Selfwhere
U: Fn(RespoEvent, DispatchFn<T>) -> Result<(), String> + 'static,
handle keydown event
sourcepub fn on_focus<U>(&mut self, handler: U) -> &mut Selfwhere
U: Fn(RespoEvent, DispatchFn<T>) -> Result<(), String> + 'static,
pub fn on_focus<U>(&mut self, handler: U) -> &mut Selfwhere
U: Fn(RespoEvent, DispatchFn<T>) -> Result<(), String> + 'static,
handle focus event
sourcepub fn on_change<U>(&mut self, handler: U) -> &mut Selfwhere
U: Fn(RespoEvent, DispatchFn<T>) -> Result<(), String> + 'static,
pub fn on_change<U>(&mut self, handler: U) -> &mut Selfwhere
U: Fn(RespoEvent, DispatchFn<T>) -> Result<(), String> + 'static,
handle change event
sourcepub fn on_named_event<U>(&mut self, name: &str, handler: U) -> &mut Selfwhere
U: Fn(RespoEvent, DispatchFn<T>) -> Result<(), String> + 'static,
pub fn on_named_event<U>(&mut self, name: &str, handler: U) -> &mut Selfwhere
U: Fn(RespoEvent, DispatchFn<T>) -> Result<(), String> + 'static,
attach a listener by event name(only a small set of events are supported)
sourcepub fn children<U>(&mut self, more: U) -> &mut Selfwhere
U: IntoIterator<Item = RespoNode<T>>,
pub fn children<U>(&mut self, more: U) -> &mut Selfwhere
U: IntoIterator<Item = RespoNode<T>>,
add children elements, index key are generated from index number
sourcepub fn children_indexed<U>(&mut self, more: U) -> &mut Selfwhere
U: IntoIterator<Item = (RespoIndexKey, RespoNode<T>)>,
pub fn children_indexed<U>(&mut self, more: U) -> &mut Selfwhere
U: IntoIterator<Item = (RespoIndexKey, RespoNode<T>)>,
add children elements, with index keys specified
sourcepub fn effect<U, V>(&mut self, args: &[V], handler: U) -> &mut Selfwhere
U: Fn(Vec<RespoEffectArg>, RespoEffectType, &Node) -> Result<(), String> + 'static,
V: Serialize + Clone,
pub fn effect<U, V>(&mut self, args: &[V], handler: U) -> &mut Selfwhere
U: Fn(Vec<RespoEffectArg>, RespoEffectType, &Node) -> Result<(), String> + 'static,
V: Serialize + Clone,
add an effect on component
sourcepub fn stable_effect<U>(&mut self, handler: U) -> &mut Selfwhere
U: Fn(Vec<RespoEffectArg>, RespoEffectType, &Node) -> Result<(), String> + 'static,
pub fn stable_effect<U>(&mut self, handler: U) -> &mut Selfwhere
U: Fn(Vec<RespoEffectArg>, RespoEffectType, &Node) -> Result<(), String> + 'static,
add an empty args effect on component, which does not update
sourcepub fn effects<U>(&mut self, more: U) -> &mut Selfwhere
U: IntoIterator<Item = RespoEffect>,
pub fn effects<U>(&mut self, more: U) -> &mut Selfwhere
U: IntoIterator<Item = RespoEffect>,
add a list of effects on component
sourcepub fn class<U>(&mut self, name: U) -> &mut Selfwhere
U: Into<String>,
pub fn class<U>(&mut self, name: U) -> &mut Selfwhere
U: Into<String>,
attach a class name for adding styles
sourcepub fn maybe_class<U>(&mut self, name: Option<U>) -> &mut Selfwhere
U: Into<String>,
pub fn maybe_class<U>(&mut self, name: Option<U>) -> &mut Selfwhere
U: Into<String>,
attach an optional class name for adding styles
sourcepub fn toggle_class<U>(&mut self, name: U, on: bool) -> &mut Selfwhere
U: Into<String>,
pub fn toggle_class<U>(&mut self, name: U, on: bool) -> &mut Selfwhere
U: Into<String>,
attach a class name, controlled by a boolean
sourcepub fn class_list<U>(&mut self, names: &[U]) -> &mut Selfwhere
U: Into<String> + Clone,
pub fn class_list<U>(&mut self, names: &[U]) -> &mut Selfwhere
U: Into<String> + Clone,
attach a list of class names for adding styles
sourcepub fn inner_text<U>(&mut self, content: U) -> &mut Selfwhere
U: Into<String>,
pub fn inner_text<U>(&mut self, content: U) -> &mut Selfwhere
U: Into<String>,
writes innerText
sourcepub fn inner_html<U>(&mut self, content: U) -> &mut Selfwhere
U: Into<String>,
pub fn inner_html<U>(&mut self, content: U) -> &mut Selfwhere
U: Into<String>,
writes innerHTML
wrap with a Rc<RefCell<T>>
to enable memory reuse and skipping in diff