Add complexity for testing out switching back and forth between child FSMs

child-switch
Sven Slootweg 7 years ago
parent e54f5c687b
commit 9317060f97

1
.gitignore vendored

@ -1 +1,2 @@
node_modules
npm-debug.log*

@ -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");
}
}
}

Loading…
Cancel
Save