每次创建一些请求事件时,我的状态机都有一个自循环。我希望将这些事件存储在针对键的本地上下文列表中,并且每次执行此自循环时,元素将附加到列表中。然后,在某个到期时间之后,例如1小时,该列表被添加到SCXML的全局上下文中。我怎样才能做到这一点?
基本上我想在触发特定操作之前聚合请求。
<state id="S02" label="REQUEST CREATED">
<onentry>
<action:trigger id="ACC1" name="EXPIRY_EVENT_expiry.sm00007" />
</onentry>
<transition event="expiry.sm00007" target="S03">
<action:trigger id="ACC2" name="TO_DO_SOMETHING" />
// add the local event list to global context
</transition>
<transition event=reqCreated" target="S02" >
// keep adding the event to local context like appending to list
</transition>
</state>
答案 0 :(得分:1)
在SCXML规范中,所有数据模型变量都是全局的,因此实际上并不存在“本地”上下文。但是您可以使用键来索引JavaScript对象。类似的东西:
<datamodel>
<data id="globalEventList"/>
<data id="localEventListMap" expr="{}"/>
<data id="localKey" expr="'foo'"/>
</datemodel>
<state id="init">
<onentry>
<script>
localEventListMap[localKey] = [];
</script>
</onentry>
<transition target="S02"/>
</state>
<state id="S02" label="REQUEST CREATED">
<onentry>
<action:trigger id="ACC1" name="EXPIRY_EVENT_expiry.sm00007" />
</onentry>
<transition event="expiry.sm00007" target="S03">
<action:trigger id="ACC2" name="TO_DO_SOMETHING" />
<script>
// add the local event list to global context
globalEventList = localEventListMap[key];
</script>
</transition>
<transition event="reqCreated" target="S02" >
<script>
// keep adding the event to local context like appending to list
localEventListMap[key].push(_event);
</script>
</transition>
</state>