Skip to content

FysomGlobal does not honor '=' destination #40

@moznuy

Description

@moznuy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions