一个listener定义
src/module/test-flow/backend/src/config/static/flowDef/listener/set00_simple.spec.js
- 1const require3 = require('require3');
- 2const assert = require3('assert');
- 3
- 4module.exports = class Listener {
- 5 constructor(context) {
- 6 this.context = context;
- 7 }
- 8
- 9 async onFlowStart(options) {
- 10 console.log('onFlowStart: ', options.startEventId);
- 11 // flowVars
- 12 const xyz = this.context.vars.get('x.y.z');
- 13 assert.equal(xyz, undefined);
- 14 this.context.vars.set('x.y.z', 'flow');
- 15 }
- 16
- 17 async onFlowEnd(options) {
- 18 console.log('onFlowEnd: ', options && options.flowRemark);
- 19 // flowVars
- 20 const xyz = this.context.vars.get('x.y.z');
- 21 assert.equal(xyz, 'flow');
- 22 }
- 23
- 24 async onNodeEnter(contextNode) {
- 25 console.log('onNodeEnter: ', contextNode._nodeDef.id);
- 26 // nodeVars
- 27 const xyz = contextNode.vars.get('x.y.z');
- 28 assert.equal(xyz, undefined);
- 29 contextNode.vars.set('x.y.z', contextNode._nodeDef.id);
- 30 }
- 31
- 32 async onNodeBegin(contextNode) {
- 33 console.log('onNodeBegin: ', contextNode._nodeDef.id);
- 34 }
- 35
- 36 async onNodeDoing(contextNode) {
- 37 console.log('onNodeDoing: ', contextNode._nodeDef.id);
- 38 }
- 39
- 40 async onNodeEnd(contextNode) {
- 41 console.log('onNodeEnd: ', contextNode._nodeDef.id);
- 42 }
- 43
- 44 async onNodeLeave(contextNode) {
- 45 console.log('onNodeLeave: ', contextNode._nodeDef.id);
- 46 // nodeVars
- 47 const xyz = contextNode.vars.get('x.y.z');
- 48 assert.equal(xyz, contextNode._nodeDef.id);
- 49 }
- 50
- 51 async onEdgeEnter(contextEdge, contextNode) {
- 52 console.log('onEdgeEnter: ', contextEdge._edgeDef.id, ' from node: ', contextNode._nodeDef.id);
- 53 }
- 54
- 55 async onEdgeTake(contextEdge, contextNode) {
- 56 console.log('onEdgeTake: ', contextEdge._edgeDef.id, ' from node: ', contextNode._nodeDef.id);
- 57 }
- 58
- 59 async onEdgeLeave(contextEdge, contextNode) {
- 60 console.log('onEdgeLeave: ', contextEdge._edgeDef.id, ' from node: ', contextNode._nodeDef.id);
- 61 }
- 62
- 63 getNodeDefOptions(contextNode /* { options }*/) {
- 64 console.log('getNodeDefOptions: ', contextNode._nodeDef.id);
- 65 }
- 66
- 67};
1. 环境对象
- this.context:流程实例环境对象
- contextNode:活动节点环境对象
- contextEdge:转移线环境对象
2. 流程实例事件
- onFlowStart:流程实例启动事件
- 1async onFlowStart(options)
- onFlowEnd:流程实例结束事件
- 1async onFlowEnd(options)
3. 活动节点事件
- onNodeEnter:活动节点进入事件
- 1async onNodeEnter(contextNode)
- onNodeBegin:活动节点开始事件
- 1async onNodeBegin(contextNode)
- onNodeDoing:活动节点执行事件
- 1async onNodeDoing(contextNode)
- onNodeEnd:活动节点结束事件
- 1async onNodeEnd(contextNode)
- onNodeLeave:活动节点离开事件
- 1async onNodeLeave(contextNode)
4. 转移线事件
- onEdgeEnter:转移线进入事件
- 1async onEdgeEnter(contextEdge, contextNode)
- onEdgeEnter:转移线进入事件
如果转移线
设置了条件表达式
,那么当onEdgeEnter
事件发生时,会自动执行条件表达式
。如果结果为true,则会继续触发onEdgeTake
事件;反之,则中止该转移线
的执行
- 1async onEdgeEnter(contextEdge, contextNode)
- onEdgeTake:转移线有效事件
- 1async onEdgeTake(contextEdge, contextNode)
- onEdgeLeave:转移线离开事件
- 1async onEdgeLeave(contextEdge, contextNode)
5. 工具方法
- getNodeDefOptions
通过重载此方法,可以提供动态修改之后的活动节点
的配置参数
- 1getNodeDefOptions(contextNode, { options })
评论: