New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include stopChild
in the first argument of the assign function
#4700
Comments
I realized there are more issues with the things I wrote. You can't actually pass a param to enqueue actions so I don't even think you can stop an actor and remove it from context without doing so imperatively. I did figure out you can enqueue an assign in place to assign and kill the child machine if I do so within the |
To be fair, this isn't a v5 problem. This was always quirky/incoherent. Even if you were able to call I wonder - do you even need to keep those actors in context? We were wondering about soft-deprecating the |
I think that would cause a bunch of different problems. The nice part about having them in context is that we don't have to discriminate unions in typescript if we need to interact with an actor directly. On top of that I can easily communicate with context how the various actor instances are maintained, I might have a single instance of one type of actor upon initialization, another conditionally, and n of this other type of actor. If you have to discriminate those unions any time you interact with them in the client or the machine itself it's going to be really painful. Imagine this scenario, I create a machine that schedules appointments. It spawns an actor that connects to my date picker component. In order to wire up those machines right now looks something like this.
If I had to do that imperatively I imagine my code would end up looking something like this. I would actually put isDatePickerActor in the machine file but this is for brevity.
This is how we use actors all the time which is also why the previous behavior of |
The union of actor types does actually cause problems too. It causes issues with |
Ideally, you wouldn't need
This is fixable, we just need to remove |
Been playing around with the children property directly instead of using context. It doesn't seem to be too bad if you rely on typescript template strings. I think it does raise the barrier of entry slightly as far as typing goes but I can't really think of anything that couldn't be achieved with this pattern and template strings. Here is what I would consider a pretty heavy edge case where you needed to split all the book and news actors from our previous discussions. typescriptlang demo |
Are these typings intentional on
|
@devanfarrell You will soon be able to use maybe-undefined actors in That should make things a lot easier. |
In the context of programming, the directive to "include stopChild in the first argument of the assign function" suggests that you need to modify a function call to include a parameter named stopChild within its first argument. The assign function is likely part of a specific programming language or framework, and it seems that you need to pass the stopChild parameter to this function. This parameter could be used to control or stop certain child processes or operations within the function. |
Here's an example of how you might modify the function call to include stopChild: // Original function call // Modified function call with |
Details
Due to the way child actors need to be stopped in V5 with the
stopChild
action. There is a lot of pain surrounding stopping actors on the whole. Presently you can spawn an actor inassign
with thespawn
function and assign it to context but you can't both stop an actor and remove it from context in the same action in the same manner. This causes some serious pain points when you need to potentially stop multiple actors. In order to do so correctly you need to enqueue a bunch of actions. Below is an example of me trying to spawn and remove actors in the setup function. I haven't actually had any luck getting this working.spawning n actors
stopping n actors
Proposed
It would be a lot cleaner if the pattern looked something more similar to spawn.
Category
XState
The text was updated successfully, but these errors were encountered: