1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
<scxml datamodel="ecmascript" initial="comparison" binding="late">
<datamodel>
<data id="year" expr="2008" />
<data id="CEO" expr="'Mr Big'" />
<data id="profitable" />
<data id="json">
{
"id": 1,
"name": "Foo",
"price": 123,
"tags": [ "Bar", "Eek" ],
"stock": {
"warehouse": 300,
"retail": 20,
}
}
</data>
</datamodel>
<script>
var x = 4;
var a = ["a", "b", "c"];
var b = [10,20,30];
</script>
<script>
var y;
if (x > 10) {
y = 'true';
} else {
y = 'false';
}
</script>
<state id="comparison">
<onentry>
<log expr="'-- Testing comparisons'" />
<log expr="'x is ' + x + ', y is ' + y" />
</onentry>
<transition cond="x >= 2" target="builtin">
<log expr="'x is greater or equal to 2'" />
</transition>
<transition cond="x < 2" target="builtin">
<log expr="'x is smaller than 2'" />
</transition>
</state>
<state id="builtin">
<onentry>
<log expr="'-- Testing built ins'" />
<if cond="In('builtin')">
<log expr="'We are in state builtin'" />
<else>
<log expr="'We are not in state builtin'" />
</else>
</if>
</onentry>
<transition target="conditionals" />
</state>
<state id="conditionals">
<onentry>
<log expr="'-- Testing conditionals'" />
<if cond="y == true">
<log expr="'x is great and y is'" />
<elseif cond="x > 3">
<log expr="'x is somewhat great and y is not'" />
</elseif>
<else>
<log expr="'x is great and y is not'" />
</else>
</if>
</onentry>
<transition target="foreach" />
</state>
<state id="foreach">
<onentry>
<log expr="'-- Testing loops'" />
<foreach array="a" item="itemA" index="indexA">
<foreach array="b" item="itemB" index="indexB">
<log expr="indexA + '.' + indexB + ' = ' + itemA + '.' + itemB" />
</foreach>
</foreach>
</onentry>
<transition target="datamodels" />
</state>
<state id="datamodels">
<datamodel>
<data id="bar" expr="'yeah, bar!'"/>
</datamodel>
<onentry>
<log expr="'-- DataModels'" />
<log expr="'year = ' + year" />
<log expr="'bar = ' + bar" />
<log expr="'json.stock.warehouse = ' + json.stock.warehouse" />
</onentry>
<transition target="syntaxerror" />
</state>
<state id="syntaxerror">
<onentry>
<log expr="'-- Syntax Error'" />
<log expr="year = ' + year" />
</onentry>
<transition event="error.execution" target="final" />
</state>
<final id="final">
<onentry>
<log expr="'Finished!'" />
</onentry>
</final>
</scxml>
|