Skip to content

Commit

Permalink
fix initial machine.to enter callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
headjump committed Jan 5, 2012
1 parent 17dbb1b commit 28fd663
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion de/headjump/superstate/SuperstateMachine.as
Expand Up @@ -95,7 +95,7 @@ public class SuperstateMachine extends Superstate {

var to_root_path:Array = SuperstateMatchineStatePathInfo(to.machine_path_info).path_from_root;

if(!from) return [[], to_root_path]; // initial state!
if(!from) return [[], to_root_path.concat(to)]; // initial state!
var from_root_path:Array = SuperstateMatchineStatePathInfo(from.machine_path_info).path_from_root;

var max_i:int = Math.max(from_root_path.length, to_root_path.length);
Expand Down
23 changes: 21 additions & 2 deletions de/headjump/superstate/test/TestSuperstate.as
Expand Up @@ -64,10 +64,14 @@ public class TestSuperstate extends OkTest {
var hooks:Function = function(id:String):Object {
return {
enter: function():void {
if(hook_output) hook_output.push("in:"+id);
if(hook_output) {
hook_output.push("in:"+id);
}
},
exit: function():void {
if(hook_output) hook_output.push("out:"+id);
if(hook_output) {
hook_output.push("out:"+id);
}
}
}
};
Expand Down Expand Up @@ -124,5 +128,20 @@ public class TestSuperstate extends OkTest {
eqArray(paths[0], [m.stateByName("tres"), m.stateByName("dos"), m.stateByName("uno")], "exits");
eqArray(paths[1], [m.stateByName("one"), m.stateByName("two"), m.stateByName("three")], "enters");
}

public function testMoveAround():void {
var history:Array = [];
var validateAndClearPath:Function = function(path:String):void {
eq(path, history.join(","), "valid path");
history.lenght = 0;
};

var m:SuperstateMachine = sampleMachine(history);

validateAndClearPath("");

m.to("three");
validateAndClearPath("in:1,in:2,in:3");
}
}
}

0 comments on commit 28fd663

Please sign in to comment.