alysivji / finite-state-machine

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

Add state change logging #36

Open sdebionne opened 2 years ago

sdebionne commented 2 years ago

StateMachine may implement a state change logger (on_state_change method) as shown in the log example

class TurnstileWithLog(Turnstile):
    def __init__(self):
        super().__init__()
        self.history = [self.state]

    def on_state_change(self, source, target):
        if source != target:
            self.history.append(target)

that keeps an history of the distinct state changes.

I will had some documentation if the feature is accepted.