Cascading named services? #2192
Unanswered
sunny-mittal
asked this question in
Ideas
Replies: 1 comment 1 reply
-
It helps to imagine the invoked services living somewhere completely remote from the parent machine, in which case the parent service isn't accessible. So there are two ways to do what you're trying to do:
const childMachine = createMachine({
// ...
}, {
services: {
parentsService: // same service as parent
}
});
// ...
on: {
EVENT_FROM_CHILD: {
actions: send((ctx, e) => ({ type: 'SOME_EVENT' }), { to: 'loading' })
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I don't know if this is a dumb idea, but I was wondering what people's thoughts were on something like the following:
I was actually under the impression that a child machine could reference the main machine services by name already but realizing this isn't the case made me wonder if this approach could work. If there's another way to accomplish the same, I'm all ears :)
My use case is with react...I call
useMachine
and can pass aservices
object that references closure variables or methods. It'd be very convenient to be able to specify "root-level" services that can be invoked by any child and still leverage the lifecycle of an invocation (onDone, onError).Beta Was this translation helpful? Give feedback.
All reactions