pub trait Component<CTX>: Sized + 'static {
type Message: 'static;
type Properties: Clone + PartialEq + Default;
fn create(props: Self::Properties, context: &mut Env<'_, CTX, Self>) -> Self;
fn update(
&mut self,
msg: Self::Message,
context: &mut Env<'_, CTX, Self>
) -> ShouldRender;
fn change(
&mut self,
_: Self::Properties,
_context: &mut Env<'_, CTX, Self>
) -> ShouldRender { ... }
fn destroy(&mut self, _context: &mut Env<'_, CTX, Self>) { ... }
}
Expand description
An interface of a UI-component. Uses self
as a model.
Required Associated Types
sourcetype Properties: Clone + PartialEq + Default
type Properties: Clone + PartialEq + Default
Properties type of component implementation.
It sould be serializable because it’s sent to dynamicaly created
component (layed under VComp
) and must be restored for a component
with unknown type.
Required Methods
sourcefn create(props: Self::Properties, context: &mut Env<'_, CTX, Self>) -> Self
fn create(props: Self::Properties, context: &mut Env<'_, CTX, Self>) -> Self
Initialization routine which could use a context.
sourcefn update(
&mut self,
msg: Self::Message,
context: &mut Env<'_, CTX, Self>
) -> ShouldRender
fn update(
&mut self,
msg: Self::Message,
context: &mut Env<'_, CTX, Self>
) -> ShouldRender
Called everytime when a messages of Msg
type received. It also takes a
reference to a context.
Provided Methods
sourcefn change(
&mut self,
_: Self::Properties,
_context: &mut Env<'_, CTX, Self>
) -> ShouldRender
fn change(
&mut self,
_: Self::Properties,
_context: &mut Env<'_, CTX, Self>
) -> ShouldRender
This method called when properties changes, and once when component created.