我想script
在评估cond
intransition
块时调用标签中定义的自定义函数。
例如,我想将函数定义为:
<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 状态机定义中完成此操作?