FrozenCanuck / Ki

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

Moving from a substate to a parent state invokes enterState #31

Open endash opened 13 years ago

endash commented 13 years ago

But the inverse (moving from a parent state to a substate invoking exitState) isn't true. This wreaks havoc if you're doing complimentary things in those methods.

FrozenCanuck commented 13 years ago

Could you expand on what you are trying to accomplish.

erichocean commented 13 years ago

As I understand it, this is what he wants to do:

App.statechart = SC.Statechart.create({
  rootState: SC.State.design({
    initialSubstate: 'CHILD',
    PARENT: SC.State.design({
      enterState: function() { console.log("PARENT:enterState()"),
      CHILD: SC.State.design({
        enterState: function() { console.log("CHILD:enterState()"),
        exitState: function() { console.log("CHILD:exitState()"),
        doSomething: function() { this.gotoState('PARENT')
      })
    })
  })
});

After calling App.statechart.initStatechart(), the following should be logged:

PARENT:enterState()
CHILD:enterState()

So far, so good. Now call App.statechart.sendAction('doSomething'). This is what endash expects to be logged:

CHILD:exitState()

This is what is actually logged:

CHILD:exitState()
PARENT:enterState()

In other words, even though the PARENT state has already been entered (and is not being exited), enterState() is called again. Seems pretty clear to me that this is a bug in the statechart framework.