You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
918 B
JavaScript

'use strict';
const machina = require("machina");
let parent = new machina.Fsm({
initialState: "one",
states: {
one: {
_onEnter: function () {
console.log(`(${this.namespace}) Parent state 1 reached`);
return this.transition("two");
}
},
two: {
_onEnter: function () {
console.log(`(${this.namespace}) Parent state 2 reached`);
return this.handle("childAction");
},
_child: {
factory: function () {
console.log("Creating child");
return createChild();
}
}
}
}
});
function createChild() {
return new machina.Fsm({
initialState: "a",
states: {
a: {
_onEnter: function () {
console.log(`(${this.namespace}) Child state A reached`);
},
childAction: function () {
return this.transition("b");
}
},
b: {
_onEnter: function () {
console.log(`(${this.namespace}) Child state B reached`);
}
}
}
})
}