Merge pull request #2681 from xosxos/patch-1
fix: add an initial state to the `system_information` example
This commit is contained in:
commit
9c93341089
1 changed files with 14 additions and 6 deletions
|
|
@ -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> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue