feat: 为状态机增加获取targetState、targetStateChain功能 #518
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
虽然状态机在内部DSL维护了状态转移规则,但在实际使用过程中
发现不能够通过当前状态+事件获取到后续可能转移到的状态,DSL转移过程除UML图外不支持代码获取
比如场景
正向状态,待审核->业务审核通过->商务审核通过->法务审核通过
反向状态,待审核->业务审核驳回
待审核->业务审核通过->商务审核驳回
待审核->业务审核通过->商务审核通过->法务审核驳回
事件是审核通过、审核拒绝
在这个场景中通过待审核初始状态+审核通过事件,能够走到正向链路的最后,这条链路可能是需要展示出去的
更加通用的情况是:
通过当前状态+事件获取后续节点,或后续状态链
如果单独再维护一套等价于DSL转移过程的代码显得有点烦琐
除此之外也为了增加代码维度对后续状态获取的透明度,当状态机状态较多时提升状态链路可预测性
基于上述情况
新增4个功能
对应单元测试
com.alibaba.cola.test.StateChainTest
具体示例
给定如下状态机
获取初始状态为STATE1, 事件为EVENT1的,状态链为