seed icon indicating copy to clipboard operation
seed copied to clipboard

`orders.perform_cmd(...)` and `orders.msg_sender()(...)` vs rendering

Open wkordalski opened this issue 3 years ago • 2 comments

Intuitively, returning () or None from future passed to orders.perform_cmd(...) means that no message should be sent to Seed mailbox. Similarly, orders.msg_sender()(None) should not send any message. And in these cases rerender should not be triggered.

But it is done differently. This is stated in documentation of seed::app::App::update_with_option. However from library user perspective there's no connection between update_with_option and perform_cmd.

I think, we should at least state this fact in documentation of perform_cmd and msg_sender, so other library users won't be surprised like I was and won't have to spend time on debugging like I had to.


My code looked like:

fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
    match msg {
        Msg::MyMsg => {
            orders.perform_cmd(async move { /* do sth that do not require rerender */; });
            orders.after_next_render(|_| Msg::MyMsg);
            orders.skip();
        }
    }
}

After finishing async move { ... }, rendering is performed and async move { ... } is started again.

wkordalski avatar Mar 09 '22 16:03 wkordalski

orders.msg_sender() is for passing into other async functions so that you can communicate back to the Seed Event Loop. Otherwise it's morally and behaviourally identical to perform_cmd.

What exactly happened that defied your expectation?

fosskers avatar Mar 11 '22 18:03 fosskers

What exactly happened that defied your expectation?

I had a future fut of type impl Future<Output = ()>. After running future fut (performed by orders.perform_cmd(fut)), rendering is triggered, although no message was sent and there is no mention about such behavior in the docs.

wkordalski avatar Mar 15 '22 22:03 wkordalski