在状态机中,处理并解析状态转换的引用。
resolveReferences(transitions)
transitions
一个由状态转换对象组成的数组,其中每个状态转换对象都具有“from”、“to”和“name”属性。无返回值。
const transitions = [
{ name: 'start', from: 'none', to: 'waiting' },
{ name: 'process', from: 'waiting', to: 'processing' },
{ name: 'complete', from: 'processing', to: 'done' }
];
const stateMachine = new StateMachine();
stateMachine.resolveReferences(transitions);
该函数会根据每个状态转换的“from”、“to”属性查找对应的状态,并将其替换为实际的状态引用。如果存在未定义的状态,将抛出异常。
例如,在上面示例中,状态转换对象中的“from”属性为“none”,但状态机中并不存在该状态,因此将抛出异常。
如果转换中存在未定义的状态,将抛出异常。