I want to invoke custom function defined in script
tag while evaluating the cond
in transition
block.
For instance I want to defined functions as:
<datamodel>
<data expr="1" id="xOccurrences"/>
<data expr="0" id="yOccurrences"/>
</datamodel>
<script>
def updateVars(hasXOccurred, hasYOccurred) {
if(hasXOccurred) xOccurrences++
if(hasYOccurred) yOccurrences++
}
def thresholdBreached(hasXOccurred, hasYOccurred) {
updateVars(hasXOccurred, hasYOccurred)
if(xOccurrences > 5 && yOccurrences > 8)
return true
return false
}
</script>
Then I want to invoke them in transition eval expression (with side-effects):
<state id="StateA">
<transition event="EventX" cond="thresholdBreached(_event.data.xOccurred, _event.data.yOccurred)" target="StateB"/>
</state>
Is it possible to accomplish this in scxml state machine definition ?