State Machine with AngularJS

3

I'm having trouble implementing a state machine using AngularJS ..

On my first try, I tried to use this made in JS: link

I could not make it work as I wished. I followed the examples and got no results. What I tried was to create a few simple steps using only console.log () to see where it went, and I finally noticed that it does not go through all the states I set, it simply runs 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)
});

result:

none
ConfigurationCtrl.js:17 onentergame
ConfigurationCtrl.js:47 game

I ended up changing the method onentermenu and leaving it equal to onleavemenu to see how it would work assync and it returns error saying that the fms.transition () method does not exist.

Can anyone help me?

    
asked by anonymous 09.10.2015 / 17:08

1 answer

1

Switch:

fsm.transition();

By:

this.transition();
    
28.10.2015 / 19:18