iced-rs / iced

A cross-platform GUI library for Rust, inspired by Elm
https://iced.rs
MIT License
24.93k stars 1.18k forks source link

I try to execute command in child component #714

Closed dancespiele closed 3 years ago

dancespiele commented 3 years ago

I try to execute a Command for async function in Iced but look that it only works in parent component, in another component implement looks like doesn't work https://github.com/dancespiele/okspiel/blob/master/src/connect/connect_node.rs#L98

In that case how can I handle an asynchronize action in a child component?

hecrj commented 3 years ago

You need to route the Command returned by ConnectNode::update all the way to your Application::update, and return it there.

In other words, you are dropping the Command here. Instead, you should write something like this:

    fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
        match message {
            Message::ConnectMessage(connect_node_msg) => {
                self.connect_node.update(connect_node_msg).map(Message::ConnectMessage)
            }
        }
    }
dancespiele commented 3 years ago

@hecrj I changed that https://github.com/dancespiele/okspiel/blob/master/src/main.rs#L47 however the async function https://github.com/dancespiele/okspiel/blob/master/src/connect/connect_node.rs#L231 is not executed according with the debugging when the button action is triggered

hecrj commented 3 years ago

That's still not completely correct. You are discarding the Command produced by ConnectNode::update and returning Command::none instead.

You need to remove the Command::none line and the semicolon after the match expression. You will end up with the function I wrote above.

dancespiele commented 3 years ago

yes thanks I didn't realize before.