Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

callbacks scope #2

Open
Sandreu opened this issue Apr 13, 2014 · 5 comments
Open

callbacks scope #2

Sandreu opened this issue Apr 13, 2014 · 5 comments

Comments

@Sandreu
Copy link

Sandreu commented Apr 13, 2014

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...?

@podefr
Copy link
Member

podefr commented Apr 13, 2014

Hey,

I'm not sure to understand. If specified, the scope (third parameter), will determine the value of thiswhen the callback (second parameter) is executed. You'd like this scope to be the state machine itself by default?

@Sandreu
Copy link
Author

Sandreu commented Apr 13, 2014

Yes that what I mean :)
Even if my code is a shortcut because I skiped the transition object

@Sandreu
Copy link
Author

Sandreu commented Apr 13, 2014

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 ;)

@Sandreu
Copy link
Author

Sandreu commented Apr 13, 2014

With the enhancement become

var fsm = new FSM({ 'foo' :[ ['e1', function () { this.advance('bar'); }] ['e2', function () { ... }, 'bar' ] ], 'bar' : [ ['e2', function () { .... }, 'foo'] ]});

@podefr
Copy link
Member

podefr commented Apr 13, 2014

Yep, I'll do it an publish a new version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants