Trait sauron::Component

source ·
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§

source

type MSG: 'static

source

type XMSG: 'static

Required Methods§

source

fn update(&mut self, msg: Self::MSG) -> Effects<Self::MSG, Self::XMSG>

Update the model of this component and return follow up and/or effects that will be executed on the next update loop

source

fn view(&self) -> Node<Self::MSG>

the view of the component

Provided Methods§

source

fn init(&mut self) -> Effects<Self::MSG, Self::XMSG>

init the component

source

fn stylesheet() -> Vec<String>
where Self: Sized,

component can have static styles

source

fn observed_attributes() -> Vec<&'static str>

specify which attribute names are observed for this Component

source

fn style(&self) -> Vec<String>

in addition, component can contain dynamic style which can change when the model is updated

source

fn component_name() -> String
where Self: Sized,

return the component name defaults to the struct simplified name

source

fn prefix_class(class_name: &str) -> String
where Self: Sized,

prefix the class bane

source

fn class_ns(class_name: &str) -> Attribute<Self::MSG>
where Self: Sized,

create a classname prepended with this component name

source

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

source

fn selector_ns(class_name: &str) -> String
where Self: Sized,

create a selector class prepended with this component name

source

fn selectors_ns(class_names: impl IntoIterator<Item = impl ToString>) -> String
where Self: Sized,

create namesspaced selector from multiple classnames

Object Safety§

This trait is not object safe.

Implementors§