'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`); } } } }) }