iced-rs / iced

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

add `Command::dispatch` as a shortcut for `Command::perform` without action #2374

Closed Fogapod closed 2 months ago

Fogapod commented 2 months ago

This function is useful when you want to send event without state. I did not find other way to do it with current api other than Command::perform(async {}, |_| Message::MyMessage) which is inconvenient and creates a useless extra future.

New api is Command::dispatch(Message::MyMessage) where

enum Message {
    MyMessage,
}
hecrj commented 2 months ago

This encourages an anti-pattern.

Messages are meant to represent real events that happened. You should not use them to manually run your application logic. Simply define helper functions instead, and call them!