Created
May 31, 2016 14:59
-
-
Save fomkin/45e7c10759cc0d7b35366727e9220fd7 to your computer and use it in GitHub Desktop.
This file contains 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
function Fsm(states) { | |
var self = this; | |
function onTransition(state, data) { | |
self.state = state; | |
self.data = data; | |
states[state](data, onTransition); | |
} | |
onTransition(Object.getOwnPropertyNames(states)[0], null); | |
} | |
var fsm = new Fsm({ | |
'first' : function(data, callback) { callback('second', 2) }, | |
'second' : function(data, callback) { callback('print', data + 3) }, | |
'print' : function(data, callback) { console.log(data); }, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment