我正在尝试为 Xstate 创建一个解释,并尝试将我在单独文件中创建的机器传递给它,如下所示:
import { Machine } from 'xstate';
const testMachine = Machine({
id: 'testMachine',
initial: 'start',
states: {
start: {
on: {
PUB_TOPIC: 'wait_micro_res',
},
},
wait_micro_res: {
on: {
MACHINE_DISCONNECTED: 'disconnection',
CONFIRMATION_RECEIVED: 'wait_order',
},
},
wait_order: {
on: {
DISCONNECTION_ORDER: 'end',
EXPERIMENT_ORDER: 'wait_measurement',
},
},
wait_measurement: {
on: {
EXPERIMENT_FINISHED: 'end',
MEASUREMENT_RECEIVED: 'receive_measurement',
},
},
receive_measurement: {
on: {
SEND_2_EXPERIMENT_MS: 'wait_measurement',
},
},
disconnection: {
on: {
RECONNECTION: 'wait_micro_res',
},
},
end: {
type: 'final',
},
},
});
export default {
testMachine,
};
我正在尝试以这种方式创建它:
import { interpret } from 'xstate/lib/interpreter';
import testMachine from '../stateMachine/index';
const machineService = interpret(testMachine)
.onTransition((state) => {
console.log(state.value);
})
.start();
但是我收到了这个错误:
TypeError: Cannot set property '_sessionid' of undefined
当我尝试在解释器的同一个文件中创建机器时,一切运行良好。我尝试登录机器,它似乎已正确导入,但我不知道是否还有其他我不知道的错误