1.加载插件
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) [year] [fullname]
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,189 @@
|
||||
**有限状态机**
|
||||
|
||||
用于编排复杂的流程业务,如订单流转,审批流程
|
||||
|
||||
# 安装
|
||||
|
||||
```
|
||||
npm install bamboo_smf -S
|
||||
```
|
||||
|
||||
# 使用
|
||||
|
||||
```
|
||||
const Smf = require('bamboo_smf');
|
||||
const circuit1 = new Smf()
|
||||
//订单正常流程
|
||||
circuit1.init('order', 'new')
|
||||
.push('new', 'order.pay')
|
||||
.push('pay', 'order.confirm', 'refund.start')
|
||||
.push('confirm', 'order.end')
|
||||
.push('end')
|
||||
|
||||
|
||||
|
||||
const circuit2 = new Smf()
|
||||
//订单退款流程
|
||||
circuit2.init('refund', 'start')
|
||||
.push('start', 'refund.reimburse')
|
||||
.push('reimburse', 'refund.end')
|
||||
.push('end')
|
||||
|
||||
const processFlow = new Smf()
|
||||
//把编排好的流程数据导入
|
||||
processFlow.setSmfDataList([
|
||||
circuit1.getSmfData(),
|
||||
circuit2.getSmfData(),
|
||||
])
|
||||
|
||||
//监听流程变更
|
||||
processFlow.on((e, paras) => {
|
||||
console.log(e,paras);
|
||||
})
|
||||
|
||||
//跳转下个流程
|
||||
processFlow.setStatus('order.new').nextTo()
|
||||
// or
|
||||
processFlow.nextTo('order.new')
|
||||
```
|
||||
|
||||
# Smf.init
|
||||
|
||||
定义初始值状态
|
||||
|
||||
```
|
||||
const circuit = new Smf()
|
||||
circuit.init('状态链名称', '初始状态')
|
||||
```
|
||||
|
||||
# Smf.push
|
||||
|
||||
添加转变内容
|
||||
|
||||
```
|
||||
circuit.push('状态名称', '下一个流程地址(区块名称.状态名称)','异常时的流程地址(区块名称.状态名称)')
|
||||
```
|
||||
|
||||
# Smf.getSmfData
|
||||
|
||||
获取全部定义的json数据
|
||||
|
||||
```
|
||||
circuit.getSmfData()
|
||||
```
|
||||
|
||||
# Smf.setSmfDataList
|
||||
|
||||
设置所有区块数据
|
||||
|
||||
```
|
||||
circuit.setSmfDataList([区块数据])
|
||||
```
|
||||
|
||||
# Smf.setStatus
|
||||
|
||||
设置当前状态
|
||||
|
||||
```
|
||||
circuit.setStatus('当前状态(区块名称.状态名称)')
|
||||
```
|
||||
|
||||
# Smf.get
|
||||
|
||||
获取当前状态的数据
|
||||
|
||||
```
|
||||
circuit.get()
|
||||
```
|
||||
|
||||
# Smf.getStatusName
|
||||
|
||||
获取当前状态的名称
|
||||
|
||||
```
|
||||
circuit.getStatusName()
|
||||
```
|
||||
|
||||
# Smf.getCurrentState
|
||||
|
||||
获取当前区域和状态
|
||||
|
||||
```
|
||||
circuit.getCurrentState()
|
||||
```
|
||||
|
||||
# Smf.getTo
|
||||
|
||||
获取当前状态的to区域和状态
|
||||
|
||||
```
|
||||
circuit.getTo()
|
||||
```
|
||||
|
||||
# Smf.getErr
|
||||
|
||||
获取当前状态的err区域和状态
|
||||
|
||||
```
|
||||
circuit.getErr()
|
||||
```
|
||||
|
||||
# Smf.start
|
||||
|
||||
触发开始状态
|
||||
|
||||
```
|
||||
circuit.start('区块名称','事件入参')
|
||||
```
|
||||
|
||||
# Smf.end
|
||||
|
||||
触发结束状态(最后一个状态)
|
||||
|
||||
```
|
||||
circuit.end('区块名称','事件入参')
|
||||
```
|
||||
|
||||
# Smf.next
|
||||
|
||||
按当前状态跳转下一个
|
||||
|
||||
```
|
||||
circuit.next('事件:to,err','跳转时可以重新定义当前状态','事件入参')
|
||||
```
|
||||
|
||||
# Smf.nextTo
|
||||
|
||||
按当前状态跳转到to
|
||||
|
||||
```
|
||||
circuit.next('跳转时可以重新定义当前状态','事件入参')
|
||||
```
|
||||
|
||||
# Smf.nextErr
|
||||
|
||||
按当前状态跳转到err
|
||||
|
||||
```
|
||||
circuit.next('跳转时可以重新定义当前状态','事件入参')
|
||||
```
|
||||
|
||||
# Smf.on
|
||||
|
||||
触发跳转时的事件
|
||||
|
||||
```
|
||||
circuit.on((e, paras) => {
|
||||
console.log(e,paras);
|
||||
/**
|
||||
e:当前状态数据: {
|
||||
status_name: 'ling',
|
||||
to: 'test.end',
|
||||
err: '',
|
||||
currentState: 'test.ling'
|
||||
}
|
||||
**/
|
||||
})
|
||||
|
||||
|
||||
```
|
||||
+59
-1060
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "bamboo",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "robin",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"glob": "^8.0.3",
|
||||
"koa": "^2.13.4"
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -13,6 +13,6 @@ require('@babel/register')({
|
||||
]
|
||||
})
|
||||
require('@babel/polyfill')
|
||||
const bamboo = require('./bamboo/bamboo')
|
||||
const bamboo = require('./bamboo/index')
|
||||
const app = new bamboo();
|
||||
// app.listen(3000);
|
||||
|
||||
Reference in New Issue
Block a user