Skip to main content

Component

Trait Component 

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

    // Required methods
    fn create(input: &Self::Input, context: &ComponentContext<Self>) -> Self;
    fn view(&self, input: &Self::Input, context: &mut ViewContext<Self>) -> View;

    // Provided methods
    fn input_changed(
        &mut self,
        _input: &Self::Input,
        _context: &ComponentContext<Self>,
    ) { ... }
    fn update(
        &mut self,
        _message: Self::Message,
        _context: &ComponentContext<Self>,
    ) { ... }
}
Expand description

A stateful unit that turns input and queued messages into a View.

Reactor calls create once, input_changed when unequal input is applied, and update for accepted queued messages. It then calls view to publish the current tree and view-time declarations.

Required Associated Types§

Source

type Input: Clone + PartialEq + 'static

Immutable parent-supplied data used to reconcile the component.

Source

type Message: 'static

A message delivered to update.

Required Methods§

Source

fn create(input: &Self::Input, context: &ComponentContext<Self>) -> Self

Creates component state from its initial input.

Source

fn view(&self, input: &Self::Input, context: &mut ViewContext<Self>) -> View

Builds the current view and records context, effect, and window declarations.

Provided Methods§

Source

fn input_changed( &mut self, _input: &Self::Input, _context: &ComponentContext<Self>, )

Responds to a new input value that differs from the current input.

Source

fn update(&mut self, _message: Self::Message, _context: &ComponentContext<Self>)

Handles one queued message.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§