ifandelse / machina.js

js ex machina - finite state machines in JavaScript
http://machina-js.org/
Other
1.93k stars 147 forks source link

Pass client to _child factory in BehavorialFsm #133

Closed colegleason closed 6 years ago

colegleason commented 7 years ago

I'm trying to have a hierarchical BehavorialFsm where the general behavior is captured in the parent and some client specific behavior is captured in the child. To do that, I need the client to be accessible to the _child factory function when the Fsm tries to fetch it. Is that possible?

ifandelse commented 6 years ago

@colegleason Many apologies for the long silence here (see #146). Here's what I'd recommend for now - and if this doesn't work, we can revisit in a new issue (also I'm assuming the factory needs access to the client b/c of needing it in the initialization behavior of the child FSM?): Try to keep that child FSM as client-state-agnostic as possible, and instead move whatever init behavior that needs the client into a initial state of that child FSM and act on the client there. The reasoning here is that the construction of a BehavioralFsm (whether creating the initial instances, or the init that happens as the parent/children transition to new states) is low-level concern of the lib that shouldn't depend directly on client state being fed to the FSM.