如何在 XState 机中执行操作发送('EVENT_NAME',{to:'something from context'})?

how in XState machine to do action send('EVENT_NAME', {to:'something from context'})?

我需要将事件发送到另一个生成的状态机,它的 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 })
  }
}

P.S.

就像在

但是我动态需要的不是消息正文而是 to: 部分

在 XState 开发人员的帮助下 https://github.com/davidkpiano/xstate/issues/1110

actions {
    actionSendMyEvent: 
             send('MY_EVENT_NAME', { to: context => context.sendTo })
    }

非常感谢 XState 开发人员和维护人员!!!