You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to pass parameters from one state to another state.
Below is a very simple example to demonstrate passing parameter into the toggle function, and getting used (console.log) in the _onEnter of the next state.
As you can see, I am digging into the internals of the __machina__ property to gain access of the currentActionArgs variable. Accessing stuff in a property with double underscore before and after just feels wrong.
What is the best way to retrieve the arguments passed in?
Thanks.
varbehavioralFsm=newmachina.BehavioralFsm({initialState: "start",states: {"start": {_next: "on"},"on": {_onEnter: function(client,args){client.history.push("turning on "+args);console.log('on.enter');console.log(getParameter(client));},_next: "off"},"off": {_onEnter: function(client,args){client.history.push("turning off "+args);console.log('off.enter');console.log(getParameter(client));},_next: "on"},},toggle: function(client,args){this.handle(client,'_next',args);}});varclient={history: []};functiongetParameter(fsm){for(variteminfsm.__machina__){returnfsm.__machina__[item].currentActionArgs;}}behavioralFsm.toggle(client,1);behavioralFsm.toggle(client,2);behavioralFsm.toggle(client,3);behavioralFsm.toggle(client,4);console.log(client.history);
The text was updated successfully, but these errors were encountered:
@george-lin Sincere apologies my long absence here (see #146). The _onEnter handlers do not accept additional arguments currently. It's something I've been asked about before, and will consider looking into for the next major version bump. The toggle function is actually telling the FSM to handle the _next input, so the argument you're passing is going to the _next handler. If you were using the function syntax as opposed to the string state name shortcut, you could console log args and see the integer being passed.
Hello,
First of all, thank you for the library.
I am trying to pass parameters from one state to another state.
Below is a very simple example to demonstrate passing parameter into the
toggle
function, and getting used (console.log) in the_onEnter
of the next state.As you can see, I am digging into the internals of the
__machina__
property to gain access of thecurrentActionArgs
variable. Accessing stuff in a property with double underscore before and after just feels wrong.What is the best way to retrieve the arguments passed in?
Thanks.
The text was updated successfully, but these errors were encountered: