FrozenCanuck / Ki

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

currentStates() only returning deepest level of state #27

Closed geoffreyd closed 13 years ago

geoffreyd commented 13 years ago

While using Master (f410bde03828fb860283) today, we ran into a bug where calling .currentStates() would always return an array of length 1, and the only state being the deepest (not any of the parent states)

Is this expected behaviour? if so, is there a way to get a list of the state tree leading upto the current state? or do I just need to loop through state = state.parentState until I find the one I want?

joshholt commented 13 years ago

If I remember correctly this used to provide an array of states leading up to the current (deepest) state. This seems to be a regression, but to be sure I will checkout an earlier commit and test.

FrozenCanuck commented 13 years ago

Yes, the behavior you are observing is correct. For example, let's say you have the following:

MyApp.statechart = Ki.Statechart.create({

  initialState: 'stateA',

  stateA: Ki.State.design({

    initialSubstate: 'stateX',

    stateX: Ki.State.design(),

    stateY: Ki.State.design()

  })

})

When you do MyApp.statechart.get('currentStates') you will get back an array containing just stateX; not an array containing stateX and stateA. For any state in a statechart, you can check if it has substates that current using either the currentSubstates or hasCurrentSubstates property. Example:

fooState.get('currentSubstates') // returns an array of substates

fooState.get('hasCurrentSubstates') // returns a boolean value

Now, as for what you are requesting, the framework does not support it. So, yes, at the moment you would have to iterate up the parent states from the current state. What is it you are trying to do with a current state's parent states?

geoffreyd commented 13 years ago

Ok, thanks for the clarification. The use case that we wanted was to use a property that was set on an action that may not always be the deepest level. This is not a usual (nor recommended) approach, but we are auto generating some states, and this was the cleanest approach.

We've fixed our issue, as seeing as we just had the wrong understanding, you can close this bug. Thank you.