Created
April 17, 2012 02:00
-
-
Save ifandelse/2402904 to your computer and use it in GitHub Desktop.
Hierarchical State Machine API ideas for machina.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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? | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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