1

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 ?

kingster
  • 47
  • 1
  • 7
phantomastray
  • 449
  • 3
  • 16
  • You approach looks like it should work. cond can call a function defined in your top-level script, and that function can have side effects. I noticed that your function definitions will have syntax errors, as they use "def" in the function declaration. – jbeard4 Dec 12 '16 at 13:47

0 Answers0