Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make On::send_event more flexible #25

Open
alice-i-cecile opened this issue Apr 19, 2024 · 3 comments
Open

Make On::send_event more flexible #25

alice-i-cecile opened this issue Apr 19, 2024 · 3 comments

Comments

@alice-i-cecile
Copy link

alice-i-cecile commented Apr 19, 2024

    pub fn send_event<F: Event + From<ListenerInput<E>>>() -> Self {

This is the current signature of On::send_event.

However, I want to be able to quickly do things like "send an AppExit event when this button is clicked".

I propose three related methods:

  1. send_event: takes an event of type F and captures it in the closure.
  2. convert_and_send_event: current behavior: converts E to F and sends it.
  3. send_default_event: sends an event with the Default value.
@alice-i-cecile
Copy link
Author

Note that in some cases, I simply can't add a From impl between the event types: orphan rules block implementations on e.g. AppExit.

@alice-i-cecile
Copy link
Author

    fn send_default_event<E: Event + Default>() -> Self {
        On::run(|mut event_writer: EventWriter<E>| {
            event_writer.send_default();
        })
    }

A working prototype of 3.

@aevyrie
Copy link
Owner

aevyrie commented May 4, 2024

We could do all three things with a single closure version:

send_event<F: Event>(impl FnMut(E)-> F>)
  1. Capture send_event(move |_| my_other_event.clone())
  2. Convert send_event(MyEvent::from)
  3. Default send_event(|_| MyEvent::default)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants