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

How does the OnTransitionCompleted work? #477

Open
flycast opened this issue Aug 19, 2022 · 0 comments
Open

How does the OnTransitionCompleted work? #477

flycast opened this issue Aug 19, 2022 · 0 comments

Comments

@flycast
Copy link

flycast commented Aug 19, 2022

I get some of the basics of stateless and really think it seems miraculous.
I am having trouble wrapping my head around some features that use concepts I don't understand.

Using in .NET, winform c# 8.0

I have a form and a class that controls a robot. I want to use stateless to keep the robot states straight in the robot class and to enable/disable menu options on the form itself. I have defined a couple simple states:

public Robot(RobotOptions settings)
{
    _robotOptions = settings;

    _stateMachine = new StateMachine<State, Trigger>(State.NotConnected);

    //Define Not Connected State
    _stateMachine.Configure(State.NotConnected)
        .Permit(Trigger.Connect, State.ConnectedNotHomed);

    //Connected not homed state
    _stateMachine.Configure(State.ConnectedNotHomed)
        .Permit(Trigger.Disconnect, State.NotConnected);

    _stateMachine.OnTransitioned(a => Log.Information($"Transitioned from: {a.Source} to {a.Destination} via {a.Trigger}."));

}
  1. Now I am clueless as to how to control the menu items on the form based on the states in the stateMachine. My first thought was to create a event in the Robot class itself and define a handler in form. The handler would get notified about the state of the stateMachine.

  2. It looks like there are a couple of events in stateless that fire before and after a state change. This seems perfect but I am not familiar with the form of the parameter that it uses. Further, I'd like the event from the state machine to notify the form class.

Is there someone who could help me with this?

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

1 participant