alysivji / finite-state-machine

Lightweight, decorator-based Python implementation of a Finite State Machine
MIT License
112 stars 12 forks source link

Available actions #19

Open alysivji opened 4 years ago

alysivji commented 4 years ago

Given the current state, what actions are available?

sammydowds commented 4 years ago

Hello Aly, I would also like to take this on. I am thinking I could add an attribute to the StateMachine class for transitions which would be a dictionary of transitions, and then add some methods to return available transitions based on sources and targets.

It looks like they do something similar with FSMMeta in django-fsm in this file.

alysivji commented 4 years ago

That makes sense. I think we do something similar for functions where we store meta information in the .__fsm attribute

alysivji commented 4 years ago

Please take this one; would love the help!

sammydowds commented 4 years ago

Hello Aly, I might need some feedback on this. What is the best place to reach out to you?

alysivji commented 4 years ago

Can you create a pull request with your changes? Would make it easier to discuss

sammydowds commented 4 years ago

Ok! I opened one! Let me know if I am way off, or if this was not what you were looking for. #22

alysivji commented 3 years ago

I think the way to do this is to change the transition from being a function decorator to being decorator created via a class with class level variables:

class TransitionDecorator:
  transition_mapping = {}

  def __init__(self):
    pass

  def __call__(self, *args, *kwargs):
    # return a decorator
    # when creating decorator, add elements to use self.__class__.transition_mapping

Class will allow us to have state saved. Need to figure out how to access this mapping from the state machine sub-class