Expand description
This module defines traits the user needs to implement a Ruukh Component.
The main traits of concern for a user are Lifecycle and Render.
The other trait which is required is the uber important
Component trait, which is automatically implemented
by using the #[component]
attribute on top of the component struct. You
are advised against to implement it yourself other than to learn how
everything wires up.
So onto implementing the Lifecycle
and Render
trait. By the way if you
desire not to write the implementation of Lifecycle
yourself, you may
write #[derive(Lifecycle)]
on your component struct.
Example
#[component]
struct Help;
impl Lifecycle for Help {}
impl Render for Help {
fn render(&self) -> Markup<Self> {
html! {
<div>
"This is help section"
</div>
<div>
"There are a lot of divs here. Here comes a "<button>"Button"</button>
</div>
}
}
}
The lifecycle implementation provided here is bare bones. Actually, lifecycle provides a default implementation which does nothing. If you want to provide a much more specific implementation, you can selectively implement its methods.
Example
impl Lifecycle for Help {
fn created(&self) {
println!("It got created just now!");
}
}
Note: Docs on component macros are located here.
Structs
Traits
#[component]
on a component struct (which
also does other magical stuff).'static
closures.