FrozenCanuck / Ki

A Statechart Framework for SproutCore
http://frozencanuck.wordpress.com
Other
105 stars 7 forks source link

Pass arguments to events and states? #17

Closed ghost closed 13 years ago

ghost commented 13 years ago

I have set some variables in one state and when i goto another state I want the new state to be able to access the previous set variables.

Is it possible to pass arguments to events and states?

FrozenCanuck commented 13 years ago

The best way to do this is pass a context value to the gotoState method where the context value contains the values you want to pass to the state you are going to.

context = { ... }; // values to pass along
gotoState('someState', context)

When the someState is entered, the context value will be passed in:

enterState(context) { ... }

A state can access another other state via the statechart property, but the problem with that approach is the amount of coupling it introduces between states, which is not ideal.

ghost commented 13 years ago

Hmm I get these 2 errors doing that:

Can not find matching subtype. value must be an object or string: [object Object]

Can not to goto state SHOWING_SIGNED_IN_VIEWS. [object Object] is not a recognized current state in statechart

ghost commented 13 years ago

It works now...I had an older version of Ki.

Great work!! =)

FrozenCanuck commented 13 years ago

Awesome. Glad to know everything is working out for you :-)