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::update,
|
||||||
Example::view,
|
Example::view,
|
||||||
)
|
)
|
||||||
.run()
|
.run_with(Example::new)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
@ -28,20 +28,28 @@ enum Message {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Example {
|
impl Example {
|
||||||
|
fn new() -> (Self, Task<Message>) {
|
||||||
|
(
|
||||||
|
Self::Loading,
|
||||||
|
system::fetch_information().map(Message::InformationReceived),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fn update(&mut self, message: Message) -> Task<Message> {
|
fn update(&mut self, message: Message) -> Task<Message> {
|
||||||
match message {
|
match message {
|
||||||
Message::Refresh => {
|
Message::Refresh => {
|
||||||
*self = Self::Loading;
|
let (state, refresh) = Self::new();
|
||||||
|
|
||||||
return system::fetch_information()
|
*self = state;
|
||||||
.map(Message::InformationReceived);
|
|
||||||
|
refresh
|
||||||
}
|
}
|
||||||
Message::InformationReceived(information) => {
|
Message::InformationReceived(information) => {
|
||||||
*self = Self::Loaded { information };
|
*self = Self::Loaded { information };
|
||||||
|
|
||||||
|
Task::none()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::none()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(&self) -> Element<Message> {
|
fn view(&self) -> Element<Message> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue