我想在评估script
块中的cond
时调用transition
标记中定义的自定义函数。
例如,我想将函数定义为:
<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>
然后我想在转换eval表达式中调用它们(带副作用):
<state id="StateA">
<transition event="EventX" cond="thresholdBreached(_event.data.xOccurred, _event.data.yOccurred)" target="StateB"/>
</state>
是否可以在scxml状态机定义中完成此操作?