我需要将事件发送到另一个生成的状态机,它的 ID 作为上下文中变量中的字符串。 (它不是父状态机,也不是子状态机)
喜欢context.sendTo = 'B_id'
怎么办send()
来自上下文的参数?
以及如何放置send('MY_EVENT_NAME', {to: <something from context> })
在 MachineOptions
actions
部分?
// this does not work...
const myMachineOptions:Partial<MachineOptions<any,any>> =
{
actions:{
mySend: (context, event)=>send('MY_EVENT_NAME', {to: context.sendTo })
}
}
附言
它就像在
Pass values when sending events from one machine to another in xState
但我需要动态的不是消息体而是
to:
部分
最佳答案
遵循 XState 开发人员的帮助 https://github.com/davidkpiano/xstate/issues/1110
actions {
actionSendMyEvent:
send('MY_EVENT_NAME', { to: context => context.sendTo })
}
非常感谢 XState 的开发者和维护者!!!
关于typescript - 如何在 XState 机器中执行操作发送 ('EVENT_NAME' , {to :'something from context' })?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60979235/