Avoid using Message to drive logic in system_information example
This commit is contained in:
parent
334f5baa10
commit
1e5c1ad2cb
1 changed files with 11 additions and 7 deletions
|
|
@ -29,23 +29,27 @@ enum Message {
|
||||||
|
|
||||||
impl Example {
|
impl Example {
|
||||||
fn new() -> (Self, Task<Message>) {
|
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> {
|
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