commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbe...@apache.org
Subject svn commit: r1032236 - /commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/AbstractStatechartGenerator.xsl
Date Sun, 07 Nov 2010 09:32:12 GMT
Author: jbeard
Date: Sun Nov  7 09:32:12 2010
New Revision: 1032236

URL: http://svn.apache.org/viewvc?rev=1032236&view=rev
Log:
Added code to support cancel element. It is now possible to cancel delayed events based on
the id of the send element.

Modified:
    commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/AbstractStatechartGenerator.xsl

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/AbstractStatechartGenerator.xsl
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/AbstractStatechartGenerator.xsl?rev=1032236&r1=1032235&r2=1032236&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/AbstractStatechartGenerator.xsl
(original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/AbstractStatechartGenerator.xsl
Sun Nov  7 09:32:12 2010
@@ -62,6 +62,7 @@
 	-->
 
 	<variable name="abstractStateName" select="'AbstractState'"/>
+	<variable name="delayedSendBaseVariableName" select="'_$timeoutId'"/>
 
 	<variable name="defaultIteratorVarName" select="concat(generate-id(),'_iterator')"/>
 	<variable name="defaultHoistVarName" select="concat(generate-id(),'_hoist')"/>
@@ -229,6 +230,12 @@
 				//variable declarations relating to data model
 				<apply-templates select=".//s:datamodel"/>
 
+				<!-- FIXME: we need to make sure that each delayed send has an id so that it can be
cancelled -->
+				//send timeout id variables
+				<call-template name="genDelayedSendTimeoutIdVariables">
+					<with-param name="delayedSends" select="//s:send[@delay]"/>
+				</call-template>
+
 				<call-template name="genEventRegularExpressions">
 					<with-param name="events" select="$allEventsEnum"/>
 				</call-template>
@@ -307,6 +314,23 @@
 		</for-each>;
 	</template>
 
+
+	<template name="genDelayedSendTimeoutIdVariables">
+		<param name="delayedSends"/>
+
+		var <for-each select="$delayedSends">
+			<value-of select="@id"/><value-of select="$delayedSendBaseVariableName"/>
+			<choose>
+				<when test="position() = last()">
+				;
+				</when>
+				<otherwise>
+				,
+				</otherwise>
+			</choose>
+		</for-each>
+	</template>
+
 	<template name="genEventRegularExpressions">
 		<param name="events"/>
 
@@ -530,7 +554,7 @@
 				<!-- TODO: think about cancel -->
 				<!-- TODO: fix GEN -->
 				//send delayed event
-				window.setTimeout(function(){
+				<value-of select="@id"/><value-of select="$delayedSendBaseVariableName"/>
= window.setTimeout(function(){
 					self['<value-of select="@event"/>'](null);
 				},<value-of select="number(@delay)*1000"/>);
 			</when>
@@ -548,7 +572,7 @@
 	</template>
 
 	<template match="s:cancel">
-	<!--TODO-->
+		window.clearTimeout(<value-of select="@sendid"/><value-of select="$delayedSendBaseVariableName"/>);
 	</template>
 
 	<template match="s:invoke">



Mime
View raw message