#create generic `sendParent` action?

1 messages · Page 1 of 1 (latest)

balmy depot
#

I need to notify a parent state machine when something happens in a child machine when its context is changed. Using sendParent (which I know isn't preferred because it is vaguely typed) was my idea, but several machines need to do this in my app. I tried extracting a sendParent action to a shared actions module, but I'm running into typing issues when I try to use it in my machines, because sendParent doesn't have a reference to the types in the machine it is being used in

Does anyone know how I could extract sendParent into a module and have it be used in multiple machines?

Besides the DRY principle, I'm also following Sandro's blog about organizing a machine's code

Thanks for any insights!

Sandro Maglione

Learn how to implement a state machine using actors in XState v5, how to organize the code for context, input, events, and actions, and how to invoke and use actors in a state machine.

noble sequoia
#

Instead of sendParent, you can send the parent via input and strongly type it there

#

sendParent is really just for convenience, but it's not possible to know what type the parent will be

grizzled bison
# balmy depot I need to notify a parent state machine when something happens in a child machin...

What's the difference between these two sites?
https://www.typeonce.dev/
https://www.sandromaglione.com/

typeonce.dev

Professional training for Full-Stack software development teams

Sandro Maglione

Passionate about technology, writing, and personal development. Ideas and essays on programming, writing, languages, storytelling, books, and games

grizzled bison
#

Oh. I thought @knotty star posted that link, that's who the question was meant for.

knotty star