Open Sandreu opened 10 years ago
Hey,
I'm not sure to understand. If specified, the scope (third parameter), will determine the value of this
when the callback (second parameter) is executed. You'd like this scope to be the state machine itself by default?
Yes that what I mean :) Even if my code is a shortcut because I skiped the transition object
It would be more like :
var fsm = new FSM(); var t; t = fsm.add('foo'): t.add('e1', function () { this.advance('bar'); }, fsm); t.add('e2', function () { ... }, fsm, 'bar'); t = fsm.add('bar'); t.add('e2', function () { ... }, fsm, 'foo');
Not cool ;)
With the enhancement become
var fsm = new FSM({ 'foo' :[ ['e1', function () { this.advance('bar'); }] ['e2', function () { ... }, 'bar' ] ], 'bar' : [ ['e2', function () { .... }, 'foo'] ]});
Yep, I'll do it an publish a new version
Hello again,
I got your scope logic with the third transition.add() parameter, but to put the fsm object context in scope, You have to add transition manually with add() after object declaration :
var fsm = new FSM(); fsm.add(['foo', function () { ... }, fsm, 'bar']); fsm.add(['bar', function () { ... }, fsm, 'foo']);
This is just a life hacking but perhaps the fsm object as default scope is nice... To keep the array init possible...?