Skip to content

Instantly share code, notes, and snippets.

@ifandelse
Created April 17, 2012 02:00
Show Gist options
  • Save ifandelse/2402904 to your computer and use it in GitHub Desktop.
Save ifandelse/2402904 to your computer and use it in GitHub Desktop.
Hierarchical State Machine API ideas for machina.js
// FSM to handle app init concerns - 90% of the time it would have linear progression through states
var appInitFsm = new machina.Fsm({
initialState: "uninitialized";
states: {
uninitialized: {
_onEnter: function() {
this.transition("initializing");
}
},
loadingTemplates: {
// handlers for this state here....
},
loadingData: {
// handlers for this state here....
},
ready: {
// maybe have _onEnter signal an event here that parent would listen for?
}
}
});
var masterFsm = new machina.Fsm({
initialState: "uninitialized";
states: {
uninitialized: {
_onEnter: function() {
this.transition("initializing");
}
},
// delegating handling of initializing state to a child Fsm
// would need to come up with a mechanism for parent Fsm to know control has been returned to it....?
// This could be the worst idea ever.
initializing: {
_delegateTo: appInitFsm,
completed: ready
}
ready: {
// other state handlers here....
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment