forked from oxplot/fysom
-
Notifications
You must be signed in to change notification settings - Fork 39
Open
Description
Small snippet to illustrate:
from fysom import FysomGlobal, FysomGlobalMixin
class Model(FysomGlobalMixin, object):
GSM = FysomGlobal(
events=[('test', ('green', 'not_important'), '=')],
initial='green',
state_field='state'
)
def __init__(self):
self.state = None
super(Model, self).__init__()
obj = Model()
print(obj.current) # 'green'
obj.test()
print(obj.current) # '='
I tried to add 2 events with the same name:
events=[('test', 'green', 'green')],
events=[('test', 'not_important', 'not_important'],
but the latter overrides the former, which do not correspond with Fysom behaviour:
from fysom import Fysom
fsm = Fysom(
events=[
('change', 'green', 'red'),
('test', 'green', 'green'),
('test', 'red', 'red')],
initial='green')
print(fsm.current) # green
fsm.test()
print(fsm.current) # green
fsm.change()
print(fsm.current) # red
fsm.test()
print(fsm.current) # red
and
from fysom import FysomGlobal, FysomGlobalMixin, Fysom
class Model(FysomGlobalMixin, object):
GSM = FysomGlobal(
events=[
('change', 'green', 'red'),
('test', 'green', 'green'),
('test', 'red', 'red')],
initial='green',
state_field='state'
)
def __init__(self):
self.state = None
super(Model, self).__init__()
obj = Model()
print(obj.current) # 'green'
obj.test() # 'fysom.FysomError: event test inappropriate in current state green'
print(obj.current)
obj.change()
print(obj.current)
obj.test()
print(obj.current)
So now I forced to create to different events and fire them based on state which defeats the point of using FSM.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels