diff options
author | 2024-09-18 22:00:40 +0200 | |
---|---|---|
committer | 2024-09-18 22:00:40 +0200 | |
commit | 9e5afc54cea74c6d06a9d3f1ae0f7372ff1e13cb (patch) | |
tree | fc26850c4b80b7b45b360968b5e55ce8d1f4f5e2 | |
parent | 1cf284a850cf13591efbf6a28a98862aaa02ba08 (diff) | |
download | iced-9e5afc54cea74c6d06a9d3f1ae0f7372ff1e13cb.tar.gz iced-9e5afc54cea74c6d06a9d3f1ae0f7372ff1e13cb.tar.bz2 iced-9e5afc54cea74c6d06a9d3f1ae0f7372ff1e13cb.zip |
Show `Action` pattern in The Pocket Guide
-rw-r--r-- | src/lib.rs | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -380,16 +380,18 @@ //! # use iced::{Element, Task}; //! # pub struct Contacts; //! # impl Contacts { -//! # pub fn update(&mut self, message: Message) -> Task<Message> { unimplemented!() } +//! # pub fn update(&mut self, message: Message) -> Action { unimplemented!() } //! # pub fn view(&self) -> Element<Message> { unimplemented!() } //! # } //! # #[derive(Debug)] //! # pub enum Message {} +//! # pub enum Action { None, Run(Task<Message>), Chat(()) } //! # } //! # mod conversation { //! # use iced::{Element, Task}; //! # pub struct Conversation; //! # impl Conversation { +//! # pub fn new(contact: ()) -> (Self, Task<Message>) { unimplemented!() } //! # pub fn update(&mut self, message: Message) -> Task<Message> { unimplemented!() } //! # pub fn view(&self) -> Element<Message> { unimplemented!() } //! # } @@ -419,7 +421,19 @@ //! match message { //! Message::Contacts(message) => { //! if let Screen::Contacts(contacts) = &mut state.screen { -//! contacts.update(message).map(Message::Contacts) +//! let action = contacts.update(message); +//! +//! match action { +//! contacts::Action::None => Task::none(), +//! contacts::Action::Run(task) => task.map(Message::Contacts), +//! contacts::Action::Chat(contact) => { +//! let (conversation, task) = Conversation::new(contact); +//! +//! state.screen = Screen::Conversation(conversation); +//! +//! task.map(Message::Conversation) +//! } +//! } //! } else { //! Task::none() //! } |