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

Determine if a state can switch to another state #131

Open
Michael-Leonardo-Cantina opened this issue Sep 1, 2017 · 4 comments
Open

Determine if a state can switch to another state #131

Michael-Leonardo-Cantina opened this issue Sep 1, 2017 · 4 comments

Comments

@Michael-Leonardo-Cantina

I have a unique use-case for these FSMs that I hope you can help me with!

I am using the FSM to track a state machine from another source. It's possible that the source could send invalid state switches... I am forcing my FSM to change to any state (using that "goto" wildcard example) but I also defined what I know to be the correct possible transitions. I would like to force my FSM switch to new state (done already), but also report that the transition was in-error because there was no defined transition that went from the beforeState to this afterState.

I can use fsm.transitions to get all possible transitions (great)... but I need to be able to see what all possible endStates are for each possible transition. Is there any way to do that?

Something like:
fsm.getAllPossibleNextStates()
or
fsm.getToState(transition)

Any help is greatly appreciated!

  • Mike
@adami
Copy link

adami commented Sep 4, 2017

from the documentation:

fsm.is(s) - return true if state s is the current state
fsm.can(t) - return true if transition t can occur from the current state
fsm.cannot(t) - return true if transition t cannot occur from the current state
fsm.transitions() - return list of transitions that are allowed from the current state
fsm.allTransitions() - return list of all possible transitions
fsm.allStates() - return list of all possible states

when getting transitions() - aren't you getting the state each transition leads you to?

@Michael-Leonardo-Cantina
Copy link
Author

Michael-Leonardo-Cantina commented Sep 7, 2017

Yes, I've seen those functions - none of them address the issue of needing to know what valid states you could be switching to based on what state you are in.

fsm.transitions() seems to only return the names of the possible transitions, but doesn't include which end-states these transitions go to. That why I would need something like fsm.getToState(transition) or something like that to then look up what states these possible transitions represent.

I appreciate you looking into this - any other ideas?

  • Mike

@adami
Copy link

adami commented Sep 10, 2017

from a quick look there's no quick way to do it, so either:

  • code and send pull request :)
  • do it the ugly way and hope nothing changes (directly access fsm._fsm.config.map[fsm.state])

@stayko
Copy link

stayko commented Apr 24, 2020

Is this still not possible?

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

3 participants