FrozenCanuck / Ki

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

Share variables between enterState and exitState? #24

Closed ghost closed 13 years ago

ghost commented 13 years ago

How do I share a variable between enterState() and exitState() because when entered I want to create an object that is destroyed on exit.

Is there a way or do I have to use a global variable?

FrozenCanuck commented 13 years ago

You don't need to create a global variable. Rather, the state itself can hold the value that is used by the state's enterState and exitState methods. Example:

fooState: Ki.State.design({

  enterState: function() {
    this._value = SC.Object.create({ ... });     
  },

  exitState: function() {
    this._value.destroy();
  }

})