Closed zeppelin closed 12 years ago
This is a flaw that was fixed in the SproutCore's 1.x version of the statechart framework; however, looks like the fix was not applied to the port in SC 2.0. Thanks for the notice. Will get fixed.
Thanks Mike. I'm keen on this fix as well.
@frozencanuck when you get this fixed, can you close this issue? Thanks mate!
@FrozenCanuck Are there any updates regarding this issue? I'd fix this if necessary, but have no idea where to start...
@zeppelin My apologies for the delayed response. Unfortunately I did not get a chance to fix the problem earlier. The problem is within the sendAction method where it does not keep track of what states have been checked when trying to handle an action. This is the current logic causing the problem:
for (; i < len; i += 1) {
actionHandled = false;
state = currentStates[i];
if (!get(state, 'isCurrentState')) continue;
while (!actionHandled && state) {
actionHandled = state.tryToHandleAction(action, arg1, arg2);
if (!actionHandled) state = get(state, 'parentState');
else statechartHandledAction = true;
}
}
This is the fix that has been applied to the statechart framework in SproutCore 1.x (currently residing in the merge_public branch):
var checkedStates = {};
for (; i < len; i += 1) {
eventHandled = NO;
state = currentStates[i];
if (!state.get('isCurrentState')) continue;
while (!eventHandled && state) {
if (!checkedStates[state.get('fullPath')]) {
eventHandled = state.tryToHandleEvent(event, arg1, arg2);
checkedStates[state.get('fullPath')] = YES;
}
if (!eventHandled) state = state.get('parentState');
else statechartHandledEvent = YES;
}
}
I have created the fix and there is now a pending pull request to bring it in:
https://github.com/emberjs-addons/sproutcore-statechart/pull/13
@FrozenCanuck thank you vm! :)
The number of times the action is called is multiplied by order the substate was defined.
Demonstration: http://shellshaper.com/sproutcore/sendaction-bug/
Code:
Output: