-
Notifications
You must be signed in to change notification settings - Fork 529
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] Implement State History #313
Comments
Hi @doanguyen, what are you looking for? Just a list of state names? Since the stateful object with transitions is the model you can use the state property to track state changes: from transitions import Machine
import collections
# if you like your machine to act as a model, let Model inherit from Machine
class Model(object):
def __init__(self, history_length):
self.state_history = collections.deque(maxlen=history_length)
@property
def state(self):
return self.state_history[-1]
@state.setter
def state(self, value):
self.state_history.append(value)
model = Model(3)
machine = Machine(model, states=['A', 'B', 'C', 'D'], initial='A')
print(model.state) # >>> A
model.to_B()
model.to_C()
model.to_A()
model.to_D()
print("->".join(model.state_history)) # >>> C->A->D |
Hi, |
States are persistent objects maintained by a You might want to have a look at this issue or this notebook to get an idea how models and database table schemes can be connected. |
Thanks a bunch! I've got it. |
As the title, it would be super helpful but I have not come up with a feasible idea yet, but people in event sourcing has done it before. Do you have time to implement or discuss it?
Btw, thanks a lot for a very good job!
The text was updated successfully, but these errors were encountered: