|
|
|
@ -4,6 +4,9 @@ const machina = require("machina");
|
|
|
|
|
|
|
|
|
|
let parent = new machina.Fsm({
|
|
|
|
|
initialState: "one",
|
|
|
|
|
memory: {
|
|
|
|
|
done: false
|
|
|
|
|
},
|
|
|
|
|
states: {
|
|
|
|
|
one: {
|
|
|
|
|
_onEnter: function () {
|
|
|
|
@ -19,9 +22,32 @@ let parent = new machina.Fsm({
|
|
|
|
|
},
|
|
|
|
|
_child: {
|
|
|
|
|
factory: function () {
|
|
|
|
|
console.log("Creating child");
|
|
|
|
|
console.log("Creating child for state 2");
|
|
|
|
|
return createChild();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
done: function () {
|
|
|
|
|
if (!this.memory.done) {
|
|
|
|
|
return this.transition("three");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
three: {
|
|
|
|
|
_onEnter: function () {
|
|
|
|
|
console.log(`(${this.namespace}) Parent state 3 reached`);
|
|
|
|
|
|
|
|
|
|
return this.handle("childAction");
|
|
|
|
|
},
|
|
|
|
|
_child: {
|
|
|
|
|
factory: function () {
|
|
|
|
|
console.log("Creating child for state 3");
|
|
|
|
|
return createChild();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
done: function () {
|
|
|
|
|
this.memory.done = true;
|
|
|
|
|
console.log("Parent done! Returning to state 2 one last time...");
|
|
|
|
|
return this.transition("two");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -42,6 +68,7 @@ function createChild() {
|
|
|
|
|
b: {
|
|
|
|
|
_onEnter: function () {
|
|
|
|
|
console.log(`(${this.namespace}) Child state B reached`);
|
|
|
|
|
return this.handle("done");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|