#How to delegate events to child machines

1 messages · Page 1 of 1 (latest)

night violet
#

I'm seeing some examples that are almost what I'm looking for but not quite:

I have a handful of small state machines that each represent a short flow a user can take on an entity. In certain cases (access control, certain screens), different flows are available to them (i.e. delete is available only on one screen). I'm trying to compose the machines together based on the screen and the user role.

Setting everything up using invoke seems to work, but how do I delegate events to the invoked child machine?

  • Hand the view a reference to the relevant child actor - render component dedicated to a certain machine depending on the active parent state, get that actorRef using actorRef.getSnapShot().children.<machineId>
  • Use the wildcard transition with sendTo to send all events to whichever child machine is currently running

Am I missing something?

night violet
dense grail
#

Can you share some code that you have so far? We can work from that

night violet
dense grail
#

Delegation is typically done via sendTo(…)

night violet
#

so instead of passing down state.children.someChildId, i'd be able to use the same actorRef and have the composite machine handle all the events?

#

For Typescript, a benefit of a view only having the child actor reference is that view can be ignorant of what other parent actor exists. I could use sendTo to send events to the parent, but my view doesn't really want to know about the parent.

#

I could see sendTo being specifically helpful if an event is coming in from somewhere else (e.g. not within the copy flow in my example) where it would cancel the flow or something, or if there were spaned child actors always running