FrozenCanuck / Ki

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

"ERROR Ki.Statechart<sc487>: Can not go to state Ki.State<sessionState.checkingUserSession.route1, sc704>. Pivot state Ki.State<__ROOT_STATE__, sc695> has concurrent substates." #21

Closed ghost closed 13 years ago

ghost commented 13 years ago

When I goto a state with gotoState() I get:

ERROR Ki.Statechart: Can not go to state Ki.State<sessionState.checkingUserSession.route1, sc704>. Pivot state Ki.State<ROOT_STATE, sc695> has concurrent substates.

Is there a way to work around this?

FrozenCanuck commented 13 years ago

Any time you get this particular error is means that you are trying to go from one state to another state that happen to have a common ancestor state (the state that will be pivoted on) where its immediate substates are concurrent. This is not allowed. For your root state, is the substatesAreConcurrent property set to true?

ghost commented 13 years ago

Yeah exactly.

But according to the guide: https://github.com/FrozenCanuck/Ki/wiki/Example-of-When-to-Use-Concurrent-States-Over-History-States this should be allowed.

I have a structure like the one in the guide.

FrozenCanuck commented 13 years ago

You are allowed concurrent substates, but take a look at the example code carefully. Notice that for both concurrent states, neither have substates that go to a state that sits outside of their respective parent states. concurrent states showPageState and menuState contain substates that are related closely to each.

When working with substates that descend from a parent state that is concurrent to other states at the same level, those substates should only ever make a reference to other substates that also descend from the same parent state. Concurrent states should be seen as modularizing states into groups where one module is independent of the other module.

This is why you are getting an error message since you have one substate trying to make a transition to another substate both of which belong to their own respective parent states that are directly concurrent to each other. That is not valid when you construct your statechart.

ghost commented 13 years ago

Yeah I get you, thats why it's weird because I have done exactly what you did on the tutorial.

Take a look at this:

http://pastie.org/1590996

FrozenCanuck commented 13 years ago

See the following:

http://groups.google.com/group/sproutcore/browse_thread/thread/4d40510ad0d36ca5

ghost commented 13 years ago

Sorry for bothering again =)

But I still don't get why I get the Pivot error because I'm just transitioning between substates that reside under the same parent that is concurrent with one other state in the same level. This should not be violating the principle that you described both in the tutorial and in the mailing list reply.

FrozenCanuck commented 13 years ago

Which state is actually invoking gotoState to go to sessionState.checkingUserSession.route1, and what is that state's parent state?

ghost commented 13 years ago

I have recreated it for easier debugging. Please have a look at: https://gist.github.com/838832

You can also paste this directly in into a Sproutcore app for debugging.

I get this error message:

ERROR Ki.Statechart: Can not go to state Ki.State<session.sessionProxy, sc695>. Pivot state Ki.State<ROOT_STATE, sc688> has concurrent substates.

FrozenCanuck commented 13 years ago

Looked at your code.

First, you don't have to do explicit console.log statements. You can just set the statechart's trace property to true and it will pump out trace statements to your browser's JS console.

As for your states, I noticed that your session's substates get into an infinite loop:

session: Ki.State.design({

  initialSubstate: "sessionProxy",

  sessionProxy: Ki.State.design({

    enterState: function() {
      Test.statechart.gotoState("checkingIfUserIsLoggedInAtYi")
    }

  }),

  checkingIfUserIsLoggedInAtYi: Ki.State.design({

    enterState: function() {
      Test.statechart.gotoState("sessionProxy")
    }

  })

})

I'm assuming your left out various logic that decides on when to switch states instead of just going ahead and doing so when you enter each.

I still need to know what state you are trying to go from. What state is it that calls gotoState that gives you this error? Actually, I need to go back and update the error message so it provides more detail.

FrozenCanuck commented 13 years ago

Get the latest Ki code. I just made an update that will provide some more details about the invalid state transition. Show me what error you get now.

ghost commented 13 years ago

Thanks for the "trace" tip. Saves me a lot of time! =)

Yes I left out some logic so in reality it won't get into an infinite loop.

I updated the Ki and now it says:

ERROR Ki.Statechart: Can not go to state Ki.State<session.sessionProxy, sc855> from Ki.State<search.showingSearch, sc887>. Pivot state Ki.State<ROOT_STATE, sc848> has concurrent substates.

ghost commented 13 years ago

That's what I don't get it. sessionProxy can go to showingSearch but not the other way around. Must be something with current Pivot state. But I didn't get how that is working.

ghost commented 13 years ago

It seems that the problem was instead of:

Testsc.statechart.gotoState()

I have to type:

this.gotoState()

Finally :)