一个listener定义

src/module/test-flow/backend/src/config/static/flowDef/listener/set00_simple.spec.js

  1. 1const require3 = require('require3');
  2. 2const assert = require3('assert');
  3. 3
  4. 4module.exports = class Listener {
  5. 5 constructor(context) {
  6. 6 this.context = context;
  7. 7 }
  8. 8
  9. 9 async onFlowStart(options) {
  10. 10 console.log('onFlowStart: ', options.startEventId);
  11. 11 // flowVars
  12. 12 const xyz = this.context.vars.get('x.y.z');
  13. 13 assert.equal(xyz, undefined);
  14. 14 this.context.vars.set('x.y.z', 'flow');
  15. 15 }
  16. 16
  17. 17 async onFlowEnd(options) {
  18. 18 console.log('onFlowEnd: ', options && options.flowRemark);
  19. 19 // flowVars
  20. 20 const xyz = this.context.vars.get('x.y.z');
  21. 21 assert.equal(xyz, 'flow');
  22. 22 }
  23. 23
  24. 24 async onNodeEnter(contextNode) {
  25. 25 console.log('onNodeEnter: ', contextNode._nodeDef.id);
  26. 26 // nodeVars
  27. 27 const xyz = contextNode.vars.get('x.y.z');
  28. 28 assert.equal(xyz, undefined);
  29. 29 contextNode.vars.set('x.y.z', contextNode._nodeDef.id);
  30. 30 }
  31. 31
  32. 32 async onNodeBegin(contextNode) {
  33. 33 console.log('onNodeBegin: ', contextNode._nodeDef.id);
  34. 34 }
  35. 35
  36. 36 async onNodeDoing(contextNode) {
  37. 37 console.log('onNodeDoing: ', contextNode._nodeDef.id);
  38. 38 }
  39. 39
  40. 40 async onNodeEnd(contextNode) {
  41. 41 console.log('onNodeEnd: ', contextNode._nodeDef.id);
  42. 42 }
  43. 43
  44. 44 async onNodeLeave(contextNode) {
  45. 45 console.log('onNodeLeave: ', contextNode._nodeDef.id);
  46. 46 // nodeVars
  47. 47 const xyz = contextNode.vars.get('x.y.z');
  48. 48 assert.equal(xyz, contextNode._nodeDef.id);
  49. 49 }
  50. 50
  51. 51 async onEdgeEnter(contextEdge, contextNode) {
  52. 52 console.log('onEdgeEnter: ', contextEdge._edgeDef.id, ' from node: ', contextNode._nodeDef.id);
  53. 53 }
  54. 54
  55. 55 async onEdgeTake(contextEdge, contextNode) {
  56. 56 console.log('onEdgeTake: ', contextEdge._edgeDef.id, ' from node: ', contextNode._nodeDef.id);
  57. 57 }
  58. 58
  59. 59 async onEdgeLeave(contextEdge, contextNode) {
  60. 60 console.log('onEdgeLeave: ', contextEdge._edgeDef.id, ' from node: ', contextNode._nodeDef.id);
  61. 61 }
  62. 62
  63. 63 getNodeDefOptions(contextNode /* { options }*/) {
  64. 64 console.log('getNodeDefOptions: ', contextNode._nodeDef.id);
  65. 65 }
  66. 66
  67. 67};

1. 环境对象

  • this.context:流程实例环境对象
  • contextNode:活动节点环境对象
  • contextEdge:转移线环境对象

2. 流程实例事件

  • onFlowStart:流程实例启动事件
  1. 1async onFlowStart(options)
  • onFlowEnd:流程实例结束事件
  1. 1async onFlowEnd(options)

3. 活动节点事件

  • onNodeEnter:活动节点进入事件
  1. 1async onNodeEnter(contextNode)
  • onNodeBegin:活动节点开始事件
  1. 1async onNodeBegin(contextNode)
  • onNodeDoing:活动节点执行事件
  1. 1async onNodeDoing(contextNode)
  • onNodeEnd:活动节点结束事件
  1. 1async onNodeEnd(contextNode)
  • onNodeLeave:活动节点离开事件
  1. 1async onNodeLeave(contextNode)

4. 转移线事件

  • onEdgeEnter:转移线进入事件
  1. 1async onEdgeEnter(contextEdge, contextNode)
  • onEdgeEnter:转移线进入事件

如果转移线设置了条件表达式,那么当onEdgeEnter事件发生时,会自动执行条件表达式。如果结果为true,则会继续触发onEdgeTake事件;反之,则中止该转移线的执行

  1. 1async onEdgeEnter(contextEdge, contextNode)
  • onEdgeTake:转移线有效事件
  1. 1async onEdgeTake(contextEdge, contextNode)
  • onEdgeLeave:转移线离开事件
  1. 1async onEdgeLeave(contextEdge, contextNode)

5. 工具方法

  • getNodeDefOptions

通过重载此方法,可以提供动态修改之后的活动节点的配置参数

  1. 1getNodeDefOptions(contextNode, { options })