pub trait Component: Sized + 'static {
type CommandOutput: Debug + Send + 'static;
type Input: Debug + 'static;
type Output: Debug + 'static;
type Init;
type Root: Debug + Clone;
type Widgets: 'static;
fn init_root() -> Self::Root;
fn init(
init: Self::Init,
root: &Self::Root,
sender: ComponentSender<Self>
) -> ComponentParts<Self>;
fn builder() -> ComponentBuilder<Self> { ... }
fn update(
&mut self,
message: Self::Input,
sender: ComponentSender<Self>,
root: &Self::Root
) { ... }
fn update_cmd(
&mut self,
message: Self::CommandOutput,
sender: ComponentSender<Self>,
root: &Self::Root
) { ... }
fn update_cmd_with_view(
&mut self,
widgets: &mut Self::Widgets,
message: Self::CommandOutput,
sender: ComponentSender<Self>,
root: &Self::Root
) { ... }
fn update_view(
&self,
widgets: &mut Self::Widgets,
sender: ComponentSender<Self>
) { ... }
fn update_with_view(
&mut self,
widgets: &mut Self::Widgets,
message: Self::Input,
sender: ComponentSender<Self>,
root: &Self::Root
) { ... }
fn shutdown(
&mut self,
widgets: &mut Self::Widgets,
output: Sender<Self::Output>
) { ... }
fn id(&self) -> String { ... }
}
Expand description
The fundamental building block of a Relm4 application.
A Component
is an element of an application that defines initialization, state, behavior and
communication as a modular unit.
Component
is powerful and flexible, but for many use-cases the SimpleComponent
convenience trait will suffice. SimpleComponent
enforces separation between model and view
updates, and provides no-op implementations for advanced features that are not relevant for most
use-cases.
Required Associated Types§
sourcetype CommandOutput: Debug + Send + 'static
type CommandOutput: Debug + Send + 'static
Messages which are received from commands executing in the background.
Required Methods§
sourcefn init(
init: Self::Init,
root: &Self::Root,
sender: ComponentSender<Self>
) -> ComponentParts<Self>
fn init(
init: Self::Init,
root: &Self::Root,
sender: ComponentSender<Self>
) -> ComponentParts<Self>
Creates the initial model and view, docking it into the component.
Provided Methods§
sourcefn builder() -> ComponentBuilder<Self>
fn builder() -> ComponentBuilder<Self>
Create a builder for this component.
sourcefn update(
&mut self,
message: Self::Input,
sender: ComponentSender<Self>,
root: &Self::Root
)
fn update(
&mut self,
message: Self::Input,
sender: ComponentSender<Self>,
root: &Self::Root
)
Processes inputs received by the component.
sourcefn update_cmd(
&mut self,
message: Self::CommandOutput,
sender: ComponentSender<Self>,
root: &Self::Root
)
fn update_cmd(
&mut self,
message: Self::CommandOutput,
sender: ComponentSender<Self>,
root: &Self::Root
)
Defines how the component should respond to command updates.
sourcefn update_cmd_with_view(
&mut self,
widgets: &mut Self::Widgets,
message: Self::CommandOutput,
sender: ComponentSender<Self>,
root: &Self::Root
)
fn update_cmd_with_view(
&mut self,
widgets: &mut Self::Widgets,
message: Self::CommandOutput,
sender: ComponentSender<Self>,
root: &Self::Root
)
Updates the model and view upon completion of a command.
Overriding this method is helpful if you need access to the widgets while processing a command output.
The default implementation of this method calls update_cmd
followed by update_view
.
If you override this method while using the component
macro, you must remember to call
update_view
in your implementation. Otherwise, the view will not reflect the updated
model.
sourcefn update_view(&self, widgets: &mut Self::Widgets, sender: ComponentSender<Self>)
fn update_view(&self, widgets: &mut Self::Widgets, sender: ComponentSender<Self>)
Updates the view after the model has been updated.
sourcefn update_with_view(
&mut self,
widgets: &mut Self::Widgets,
message: Self::Input,
sender: ComponentSender<Self>,
root: &Self::Root
)
fn update_with_view(
&mut self,
widgets: &mut Self::Widgets,
message: Self::Input,
sender: ComponentSender<Self>,
root: &Self::Root
)
Updates the model and view when a new input is received.
Overriding this method is helpful if you need access to the widgets while processing an input.
The default implementation of this method calls update
followed by update_view
. If
you override this method while using the component
macro, you must remember to
call update_view
in your implementation. Otherwise, the view will not reflect the
updated model.