From 28fd663bf8891d0a3c04712348e0225c4ff1ccfa Mon Sep 17 00:00:00 2001
From: Dennis Treder
Date: Thu, 5 Jan 2012 12:50:28 +0100
Subject: [PATCH] fix initial machine.to enter callbacks
---
de/headjump/superstate/SuperstateMachine.as | 2 +-
de/headjump/superstate/test/TestSuperstate.as | 23 +++++++++++++++++--
2 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/de/headjump/superstate/SuperstateMachine.as b/de/headjump/superstate/SuperstateMachine.as
index b9cea90..a5eb0cb 100644
--- a/de/headjump/superstate/SuperstateMachine.as
+++ b/de/headjump/superstate/SuperstateMachine.as
@@ -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);
diff --git a/de/headjump/superstate/test/TestSuperstate.as b/de/headjump/superstate/test/TestSuperstate.as
index 214dad2..5a6837b 100644
--- a/de/headjump/superstate/test/TestSuperstate.as
+++ b/de/headjump/superstate/test/TestSuperstate.as
@@ -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);
+ }
}
}
};
@@ -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");
+ }
}
}
\ No newline at end of file