-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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 RefreshState
resource and support same-state transitions
#13361
Conversation
I personally dislike this approach, for two reasons:
I think other approaches can be found for this - and it was a useful exploration - but ultimately I do not think it's a good choice here. |
The first concern is understandable. Personally I think the benefits of this PR are worth the tradeoff of very slightly relaxing the purity of computed states:
Every approach will have tradeoffs. If the only downside of this PR is giving up a tiny amount of purity in an opt-in escape hatch, I think that's a win. Especially in the context of a game engine.
Refreshes can't happen by accident with this approach. They only happen if you explicitly call |
Closing this PR in favor of the 3rd-party solution I published: https://github.com/benfrankel/pyri_state. In Hopefully |
Objective
Solution
Allow same-state transitions for freely mutable states via
next_state.set(current_state)
. Support same-state transitions for computed states via a newRefreshState<S>
resource that explicitly flags a specific computed state to transition regardless of whether its value changes.RefreshState
can be understood as a limitedNextState
for computed states that can only trigger same-state transitions, necessary because same-state transitions for computed states cannot be implicitly assumed.Testing
cargo run --example alien_cake_addict
.RefreshState
. This will require a new unit test and example.Changelog
RefreshState<S>
to flag a computed or sub state to transition regardless of whether its value changes.Migration Guide
NextState<S>
can now trigger state transitions from the current state to itself. To preserve the old behavior, check the current state inState<S>
before setting the next state.