Avoid using Message to drive logic in system_information example

This commit is contained in:
Héctor Ramón Jiménez 2024-12-03 01:27:26 +01:00
parent 334f5baa10
commit 1e5c1ad2cb
No known key found for this signature in database
GPG key ID: 7CC46565708259A7

View file

@ -29,23 +29,27 @@ enum Message {
impl Example {
fn new() -> (Self, Task<Message>) {
(Self::Loading, Task::done(Message::Refresh))
(
Self::Loading,
system::fetch_information().map(Message::InformationReceived),
)
}
fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::Refresh => {
*self = Self::Loading;
let (state, refresh) = Self::new();
return system::fetch_information()
.map(Message::InformationReceived);
*self = state;
refresh
}
Message::InformationReceived(information) => {
*self = Self::Loaded { information };
Task::none()
}
}
Task::none()
}
fn view(&self) -> Element<Message> {