pub trait Component {
type MSG: 'static;
type XMSG: 'static;
// Required methods
fn update(&mut self, msg: Self::MSG) -> Effects<Self::MSG, Self::XMSG>;
fn view(&self) -> Node<Self::MSG>;
// Provided methods
fn init(&mut self) -> Effects<Self::MSG, Self::XMSG> { ... }
fn stylesheet() -> Vec<String>
where Self: Sized { ... }
fn observed_attributes() -> Vec<&'static str> { ... }
fn style(&self) -> Vec<String> { ... }
fn component_name() -> String
where Self: Sized { ... }
fn prefix_class(class_name: &str) -> String
where Self: Sized { ... }
fn class_ns(class_name: &str) -> Attribute<Self::MSG>
where Self: Sized { ... }
fn classes_ns_flag(
pair: impl IntoIterator<Item = (impl ToString, bool)>
) -> Attribute<Self::MSG>
where Self: Sized { ... }
fn selector_ns(class_name: &str) -> String
where Self: Sized { ... }
fn selectors_ns(
class_names: impl IntoIterator<Item = impl ToString>
) -> String
where Self: Sized { ... }
}
Expand description
A component has a view and can update itself.
The update function returns an effect which can contain follow ups and effects. Follow ups are executed on the next update loop of this component, while the effects are executed on the parent component that mounts it.
Required Associated Types§
Required Methods§
Provided Methods§
sourcefn stylesheet() -> Vec<String>where
Self: Sized,
fn stylesheet() -> Vec<String>where
Self: Sized,
component can have static styles
sourcefn observed_attributes() -> Vec<&'static str>
fn observed_attributes() -> Vec<&'static str>
specify which attribute names are observed for this Component
sourcefn style(&self) -> Vec<String>
fn style(&self) -> Vec<String>
in addition, component can contain dynamic style which can change when the model is updated
sourcefn component_name() -> Stringwhere
Self: Sized,
fn component_name() -> Stringwhere
Self: Sized,
return the component name defaults to the struct simplified name
sourcefn prefix_class(class_name: &str) -> Stringwhere
Self: Sized,
fn prefix_class(class_name: &str) -> Stringwhere
Self: Sized,
prefix the class bane
sourcefn class_ns(class_name: &str) -> Attribute<Self::MSG>where
Self: Sized,
fn class_ns(class_name: &str) -> Attribute<Self::MSG>where
Self: Sized,
create a classname prepended with this component name
sourcefn classes_ns_flag(
pair: impl IntoIterator<Item = (impl ToString, bool)>
) -> Attribute<Self::MSG>where
Self: Sized,
fn classes_ns_flag(
pair: impl IntoIterator<Item = (impl ToString, bool)>
) -> Attribute<Self::MSG>where
Self: Sized,
create namespaced class names to pair that evaluates to true
sourcefn selector_ns(class_name: &str) -> Stringwhere
Self: Sized,
fn selector_ns(class_name: &str) -> Stringwhere
Self: Sized,
create a selector class prepended with this component name
sourcefn selectors_ns(class_names: impl IntoIterator<Item = impl ToString>) -> Stringwhere
Self: Sized,
fn selectors_ns(class_names: impl IntoIterator<Item = impl ToString>) -> Stringwhere
Self: Sized,
create namesspaced selector from multiple classnames