Permalink
Browse files

Updated optimized transition loaders to support multiple events on a …

…single transition. Tested and works.
  • Loading branch information...
1 parent d22ba2e commit 3a5a5be4eb64a9acb89124bd57f27f322c411a39 @jbeard4 committed Feb 22, 2012
@@ -47,23 +47,23 @@ define ["optimization/initializer","lib/beautify"],(initializer,js_beautify)->
#NOTE: scxmlJson.events will not contain wildcard ("*") event,
#and will normalize events like "foo.bat.*" to "foo.bat"
- for own eventName,event of scxmlJson.events
- transitionsForEvent = (initializer.transitionToVarLabel transition for transition in state.transitions when transition.event == event.name)
+ for own eventName of scxmlJson.events
+ transitionsForEvent = (initializer.transitionToVarLabel transition for transition in state.transitions when transition.events and eventName in transition.events )
if transitionsForEvent.length
- classStr += generateMethod event.name,transitionsForEvent,parent
+ classStr += generateMethod eventName,transitionsForEvent,parent
- defaultTransitionsForEvent = (initializer.transitionToVarLabel transition for transition in state.transitions when not transition.event)
+ defaultTransitionsForEvent = (initializer.transitionToVarLabel transition for transition in state.transitions when not transition.events)
if defaultTransitionsForEvent.length
classStr += generateMethod DEFAULT_EVENT_NAME,defaultTransitionsForEvent,parent
- wildcardTransitionsForEvent = (initializer.transitionToVarLabel transition for transition in state.transitions when transition.event is "*")
+ wildcardTransitionsForEvent = (initializer.transitionToVarLabel transition for transition in state.transitions when transition.events and "*" in transition.events)
if wildcardTransitionsForEvent.length
classStr += generateMethod WILDCARD_EVENT_NAME,wildcardTransitionsForEvent,parent
else
#root state
- for eventName,event of scxmlJson.events
- classStr += "this['#{event.name}'] = function(){return null;};\n"
+ for own eventName of scxmlJson.events
+ classStr += "this['#{eventName}'] = function(){return null;};\n"
classStr += "this['#{DEFAULT_EVENT_NAME}'] = function(){return null;};\n"
classStr += "this['#{WILDCARD_EVENT_NAME}'] = function(){return null;};\n"
@@ -71,9 +71,9 @@ define ["optimization/initializer","lib/beautify"],(initializer,js_beautify)->
(scxmlJson,beautify=true,asyncModuleDef=true) ->
#NOTE: scxmlJson.events will not contain wildcard ("*") event,
#and will normalize events like "foo.bat.*" to "foo.bat"
- stateTransitionTable = (((initializer.transitionToVarLabel transition for transition in state.transitions when transition.event == event.name) for eventName,event of scxmlJson.events ) for state in scxmlJson.states)
- wildcardTransitionsForStates = ((initializer.transitionToVarLabel transition for transition in state.transitions when transition.event is "*") for state in scxmlJson.states)
- defaultTransitionsForStates = ((initializer.transitionToVarLabel transition for transition in state.transitions when not transition.event) for state in scxmlJson.states)
+ stateTransitionTable = (((initializer.transitionToVarLabel transition for transition in state.transitions when transition.events and eventName in transition.events) for eventName of scxmlJson.events ) for state in scxmlJson.states)
+ wildcardTransitionsForStates = ((initializer.transitionToVarLabel transition for transition in state.transitions when transition.events and "*" in transition.events) for state in scxmlJson.states)
+ defaultTransitionsForStates = ((initializer.transitionToVarLabel transition for transition in state.transitions when not transition.events) for state in scxmlJson.states)
toReturn = initializer.genOuterInitializerStr scxmlJson,"""
var stateTransitionTable = #{tableToString stateTransitionTable},
wildcardTransitionTable = #{defaultTableToString wildcardTransitionsForStates},
@@ -24,8 +24,8 @@ define ["optimization/initializer","lib/beautify"],(initializer,js_beautify)->
for state in scxmlJson.states when state.transitions.length
- wildcardTransitions = (initializer.transitionToVarLabel transition for transition in state.transitions when transition.event is "*" )
- defaultTransitions= (initializer.transitionToVarLabel transition for transition in state.transitions when not transition.event)
+ wildcardTransitions = (initializer.transitionToVarLabel transition for transition in state.transitions when transition.events and "*" in transition.events)
+ defaultTransitions= (initializer.transitionToVarLabel transition for transition in state.transitions when not transition.events)
toReturn += """
case "#{state.id}":
@@ -55,13 +55,13 @@ define ["optimization/initializer","lib/beautify"],(initializer,js_beautify)->
switch(eventName){
"""
- for eventName,event of scxmlJson.events
+ for own eventName of scxmlJson.events
#NOTE: scxmlJson.events will not contain wildcard ("*") event,
#and will normalize events like "foo.bat.*" to "foo.bat"
- transitionsForEvent = (initializer.transitionToVarLabel transition for transition in state.transitions when transition.event == event.name)
+ transitionsForEvent = (initializer.transitionToVarLabel transition for transition in state.transitions when transition.events and eventName in transition.events)
if transitionsForEvent.length
toReturn += """
- case "#{event.name}":
+ case "#{eventName}":
transitions = transitions.concat(#{initializer.arrayToIdentifierListString transitionsForEvent});
break;
"""
@@ -168,6 +168,7 @@ define ["scxml/state-kinds-enum"],(stateKinds) ->
#wildcard "*" event will show up on transition.events, but will not show up in uniqueEvents
+ #default transitions (those without events) will have events set to undefined (rather than empty array)
if attributes.event
events =
if attributes.event is "*" then [attributes.event]

0 comments on commit 3a5a5be

Please sign in to comment.