pub trait Component: Sized {
type Message: 'static;
type Properties: Hash + 'static;
// Required methods
fn new(props: Self::Properties) -> Self;
fn view(&self, behavior: &mut impl Behavior<Self>) -> VNode;
fn update(&mut self, message: Self::Message) -> bool;
}
Expand description
Trait for defining custom component.
It adapts a MVC pattern. Model is the fields and state of the component. It is initialized by new function using Properties. View is the function view that returns a view of an application. Controller is the function update that updates the model based on the Message.
Required Associated Types§
Sourcetype Message: 'static
type Message: 'static
Type to describe the message that can be sent to the component. It is used to update the model of the component.
Sourcetype Properties: Hash + 'static
type Properties: Hash + 'static
Type to describe the properties that can be passed to the component. It is used to initialize the model of the component.
Required Methods§
Sourcefn new(props: Self::Properties) -> Self
fn new(props: Self::Properties) -> Self
Function that creates a new instance of the component therefore initialize a model using Properties.
Sourcefn view(&self, behavior: &mut impl Behavior<Self>) -> VNode
fn view(&self, behavior: &mut impl Behavior<Self>) -> VNode
Function that returns a view of the component. It uses Behavior to create Callbacks that are responsible to send Messages to the component. Defining the views is done using rsx macro. Using the macro is not mandatory but it is recommended and makes in unnecessary to know the complex structure of VNode.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.