invoking custom function in transition cond evaluation in scxml

217 Views Asked by At

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 ?

0

There are 0 best solutions below