Skip to content

What is the xState way to compose side-effects with Inversion of Control? #1326

Answered by davidkpiano
jLouzado asked this question in General
Discussion options

You must be logged in to vote

The control/composability lies in being able to control what gets spawned. So if you wanted e.g., a custom fetcher, then this should stay the same:

invoke: {
  src: 'fetcher',
  // ...
}

And then controlled via options:

{
  services: {
    fetcher: () => createMachine(childMachineWithCaching)
  }
}

So, to answer your question, you wouldn't try to control the behavior of an invoked actor (that breaks the actor model); rather, you would create an invoked actor with the behavior you want.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@jLouzado
Comment options

Comment options

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