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

Order of State changes and OnTransitionCompleted execution. #446

Open
kagerouttepaso opened this issue Apr 13, 2021 · 1 comment
Open

Order of State changes and OnTransitionCompleted execution. #446

kagerouttepaso opened this issue Apr 13, 2021 · 1 comment

Comments

@kagerouttepaso
Copy link

kagerouttepaso commented Apr 13, 2021

Hello.

I found that the order of the stateMutator call (updating the State) and the OnTransitionCompleted call is different in ReEntry and otherwise.

In the following source code, the order of the calls seems to be different.

private void HandleReentryTrigger(object[] args, StateRepresentation representativeState, Transition transition)
{
StateRepresentation representation;
transition = representativeState.Exit(transition);
var newRepresentation = GetRepresentation(transition.Destination);
if (!transition.Source.Equals(transition.Destination))
{
// Then Exit the final superstate
transition = new Transition(transition.Destination, transition.Destination, transition.Trigger, args);
newRepresentation.Exit(transition);
_onTransitionedEvent.Invoke(transition);
representation = EnterState(newRepresentation, transition, args);
_onTransitionCompletedEvent.Invoke(transition);
}
else
{
_onTransitionedEvent.Invoke(transition);
representation = EnterState(newRepresentation, transition, args);
_onTransitionCompletedEvent.Invoke(transition);
}
State = representation.UnderlyingState;
}

private void HandleTransitioningTrigger( object[] args, StateRepresentation representativeState, Transition transition)
{
transition = representativeState.Exit(transition);
State = transition.Destination;
var newRepresentation = GetRepresentation(transition.Destination);
//Alert all listeners of state transition
_onTransitionedEvent.Invoke(transition);
var representation = EnterState(newRepresentation, transition, args);
// Check if state has changed by entering new state (by fireing triggers in OnEntry or such)
if (!representation.UnderlyingState.Equals(State))
{
// The state has been changed after entering the state, must update current state to new one
State = representation.UnderlyingState;
}
_onTransitionCompletedEvent.Invoke(new Transition(transition.Source, State, transition.Trigger, transition.Parameters));
}

I think the order of the calls should be more consistent.

@HenningNT
Copy link
Contributor

I think you are correct.

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

No branches or pull requests

2 participants