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

Add On::set_next_state #26

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

Add On::set_next_state #26

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

Comments

@alice-i-cecile
Copy link

This is a common simple pattern that uses a surprising amount of boilerplate. We could simplify this to a single method call.

@alice-i-cecile
Copy link
Author

alice-i-cecile commented Apr 19, 2024

A simple working prototype:

    fn set_next_state<S: States + Clone>(next_state: S) -> Self {
        On::run(move |mut state: ResMut<NextState<S>>| {
            state.set(next_state.clone());
        })
    }

The Clone bound is required as NextState::set takes ownership, and we need to be able to reuse the callback.

@aevyrie
Copy link
Owner

aevyrie commented May 4, 2024

You might want to change this to take a closure instead, like mentioned here: #25

That would avoid the need for Clone, and you would be able to react to the contents of the event that is causing a state change.

set_next_state<S: States>(impl FnMut(E) -> S) -> Self

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