Merge pull request #2681 from xosxos/patch-1

fix: add an initial state to the `system_information` example
This commit is contained in:
Héctor 2024-12-03 01:35:41 +01:00 committed by GitHub
commit 9c93341089
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,7 +7,7 @@ pub fn main() -> iced::Result {
Example::update,
Example::view,
)
.run()
.run_with(Example::new)
}
#[derive(Default)]
@ -28,20 +28,28 @@ enum Message {
}
impl Example {
fn new() -> (Self, Task<Message>) {
(
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> {