Initial commit
commit
e54f5c687b
@ -0,0 +1 @@
|
||||
node_modules
|
@ -0,0 +1,31 @@
|
||||
# machina-factory-bugcase
|
||||
|
||||
A demonstration of a bug in machina v2.0.2, where a child FSM factory is called multiple times when specified as part of a config object.
|
||||
|
||||
What should happen:
|
||||
|
||||
```
|
||||
(fsm.0) Parent state 1 reached
|
||||
Creating child
|
||||
(fsm.1) Child state A reached
|
||||
(fsm.0) Parent state 2 reached
|
||||
Creating child
|
||||
(fsm.2) Child state A reached
|
||||
(fsm.2) Child state B reached
|
||||
```
|
||||
|
||||
What happens instead:
|
||||
|
||||
```
|
||||
(fsm.0) Parent state 1 reached
|
||||
Creating child
|
||||
(fsm.1) Child state A reached
|
||||
Creating child
|
||||
(fsm.2) Child state A reached
|
||||
(fsm.0) Parent state 2 reached
|
||||
Creating child
|
||||
(fsm.3) Child state A reached
|
||||
Creating child
|
||||
(fsm.4) Child state A reached
|
||||
(fsm.4) Child state B reached
|
||||
```
|
@ -0,0 +1,49 @@
|
||||
'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`);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "machina-factory-bugcase",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@git.cryto.net:joepie91/machina-factory-bugcase.git"
|
||||
},
|
||||
"keywords": ["machina"],
|
||||
"author": "Sven Slootweg <admin@cryto.net>",
|
||||
"license": "WTFPL",
|
||||
"dependencies": {
|
||||
"machina": "^2.0.2"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue