tryChangeState
签名
function tryChangeState( from: string | string[], to: string, opt?: ChangeOption): void源码
export function tryChangeState( from: string | string[], to: string, opt: ChangeOption = { ignoreError: true }) { ChangeState(from, to, opt)}ChangeState(from, to, opt) 返回一个 (target, propertyKey, descriptor) => void 装饰器函数,但 tryChangeState 既不返回它,也不应用它。
如果你需要「尝试变更」
请直接使用 @ChangeState 配合 ignoreError: true:
@ChangeState('idle', 'done', { ignoreError: true })async fetch() { await mayFail()}失败时会返回 FSMError 而非 reject,状态自动回滚。