Skip to main content

Component

Trait Component 

Source
pub trait Component: Sized + 'static {
    type Message: 'static;
    type Properties: Clone + PartialEq + Default;

    // Required methods
    fn create(props: Self::Properties, link: ComponentLink<Self>) -> Self;
    fn update(&mut self, msg: Self::Message) -> ShouldRender;

    // Provided methods
    fn change(&mut self, _: Self::Properties) -> ShouldRender { ... }
    fn on_mount(&mut self, _node: &Node) { ... }
}
Expand description

An interface of a UI-component. Uses self as a model.

Required Associated Types§

Source

type Message: 'static

Control message type which update loop get.

Source

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§

Source

fn create(props: Self::Properties, link: ComponentLink<Self>) -> Self

Initialization routine which could use a context.

Source

fn update(&mut self, msg: Self::Message) -> ShouldRender

Called everytime when a messages of Msg type received. It also takes a reference to a context.

Provided Methods§

Source

fn change(&mut self, _: Self::Properties) -> ShouldRender

This method called when properties changes, and once when component created.

Source

fn on_mount(&mut self, _node: &Node)

This method is called when the component is first mounted. It does not wait for children to render, only the top-level DOM element.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T> Component for Select<T>
where T: PartialEq + Clone + 'static,