Skip to content

Upgrading to XState v5: event meta - or alternatives #4870

Answered by davidkpiano
Poliziano asked this question in Q&A
Discussion options

You must be logged in to vote

XState v5 no longer has _event.origin (or SCXML events in general) as that was part of our API simplification. Events should now explicitly pass a self-reference if they want event consumers know where it came from:

assign({
  subscriptions: ({ context, event }) => ({
    event.sender; // property name is custom
    // ...
  })
})

// other machine
actions: sendTo('parentMachine', ({ self }) => ({
  type: 'someEvent',
  sender: self
})

Also, XState now has a built-in event emitter, which may be useful to you: https://stately.ai/docs/event-emitter

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Poliziano
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants