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

feature request: return to previous state #439

Open
bernarde01 opened this issue May 29, 2024 · 2 comments
Open

feature request: return to previous state #439

bernarde01 opened this issue May 29, 2024 · 2 comments

Comments

@bernarde01
Copy link

Thanks for an awesome tool!

I have a state machine that can go to an "ask if exit" state from every state. It would be great if I could define this ask_if_exit as a single state, and then enable this state to transition back to the previous state if the user does not want to exit.

This means that this transition will need to be dynamically defined. I have tried to do this using the library, but no luck. I forked the repo to see if I can implement this, but I don't see how this would be possible.

@fgmacedo
Copy link
Owner

fgmacedo commented Sep 9, 2024

Hi @bernarde01, how are you? Thanks for your suggestion! I really liked it and believe it would be a great addition to the library.

I’m still exploring how to implement this. A related concept in the literature is history pseudo-states, which are defined in the SCXML standard: https://www.w3.org/TR/scxml/#history.

If we can incorporate both history and compound states, this could become a viable solution.

I have an ongoing effort to add support for compound states in this PR: #329. I’m working on refining this into a non-breaking API, but it’s a significant and complex task.

@collindutter
Copy link

@fgmacedo could somehow source be used here? Something like:

def on_ask_if_exit(self, source: State) -> None:
      user_input = input("Answer: ")

      if user_input == "exit":
          self.send("exit")
      else:
          # Return to the previous state
          self.current_state = source

Unfortunately setting current_state does not trigger any Actions which is required for my use-case.

Love the library btw!

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

3 participants