lucywang000 / clj-statecharts

State Machine and StateCharts for Clojure(Script)
https://lucywang000.github.io/clj-statecharts/
Eclipse Public License 1.0
229 stars 15 forks source link

Support for History states #17

Open amithgeorge opened 1 year ago

amithgeorge commented 1 year ago

The statecharts website has an article on what are history states. From the article,

A history state is a pseudostate, meaning that a state machine can’t rest in a history state. When a transition that leads to a history state happens, the history state itself doesn’t become active, rather the “most recently visited state” becomes active. It is a way for a compound state to remember (when it exits) which state was active, so that if the compound state ever becomes active again, it can go back to the same active substate, instead of blindly following the initial transition.

Does clj-statecharts support history states? I had a need for this. My states were simple enough that I got by with adding a guarded "always" transition to the initial state that moved it to its sibling state.

lucywang000 commented 1 year ago

No it doesn't support history state at this moment.

History state by its nature is stateful, but the core of clj-statecharts is pure functional so to implement this, we need to add a new key in the fsm to manage the stateful part, much like the :scheduler key for handling the delayed transitions.

Due to my own experience i don't quite understand the typical use case of history states. Can you educate me on this?