qmuntal / stateless

Go library for creating finite state machines

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get the super state of hierarchical state?

kaundinya5 opened this issue · comments

I have states called in_review,verifying and waiting_for_decisions that are all a substate of processing. I want the user to only know that it's in processing if it's in any of these substates. I know that I can do IsInState and verify if it's processing. But is there a way to directly get the super state for all of the substates?

IsInState (and IsInStateCtx) should return true if the current state is equal to, or a substate of, the supplied state, so if I understand correctly it will already work for your use-case.

But I want to show the super state to the user(I have other super states too).Is there a function like StateMachine.State that return the super state and not precise current state? Essentially I don't want to write a Switch case to check if the state I'm in is part of a super state or not using IsInState

@kaundinya5 IMO writing a switch case that customizes what you want to display to your clients is not a bad solution. I would rather not grow stateless trying to cover the visualization needs of each use case, but just provide the foundations so users can do it themselves.

Ah, okay. Do let me know if I can create a PR with this functionality.