3
I’m having trouble implementing a state machine using Angularjs..
On my first try, I tried using this one made in JS: https://github.com/jakesgordon/javascript-state-machine
I could not make it work as I wanted. I followed the examples and did not get results. What I tried was to create a few simple steps using only console log.() to see where she was going, and eventually I noticed that it doesn’t go through all the states that I defined, it simply executes the first state:
angular.module('app').controller('ConfigurationCtrl', function($scope, $http){
$scope.welcome = "Welcome to the jungle"
$scope.percentBar = 0;
var fsm = StateMachine.create({
events: [
{ name: 'play', from: 'none', to: 'game' },
{ name: 'quit', from: 'game', to: 'teste' },
{ name: 'stop', from: 'teste', to: 'game' }
],
callbacks: {
onentermenu: function() { console.log("onentermenu"); },
onentergame: function() { console.log("onentergame"); },
onenterteste: function() {console.log("onenterteste")},
onleavemenu: function() {
trace("onleavemenu");
$http.get("http://192.168.11.51:8080/sigetall").sucess(function (data) {
console.log(data);
fsm.transition();
});
return StateMachine.ASYNC;
},
onleavegame: function() {
console.log("fuck")
$http.get("http://192.168.11.51:8080/sigetall").sucess(function (data) {
console.log(data);
fsm.transition();
});
return StateMachine.ASYNC;
},
onleaveteste: function() {
}
}
});
console.log(fsm.current)
fsm.play();
console.log(fsm.current)
});
outworking:
none
ConfigurationCtrl.js:17 onentergame
ConfigurationCtrl.js:47 game
I ended up changing the onentermenu method and leaving it equal to onleavemenu to see how it would work assync and it returns error saying the method fms.Transition() there is no.
Can someone help me?