The communication docs don't make clear if changing the context in the parent will affect the children machines:
state: {
invoke: {
id: "foo",
src: bar,
data: { baz: ctx => ctx.baz }
},
on: {
TYPE: {
actions: assign({ baz: (ctx, ev) => ev.baz })
}
}
}
When the parent machine receives TYPE and reassigns context.baz, the child machine will also update its baz context?
It would be great to update the docs to explain that behavior. If you agree, I can make a PR.
When the parent machine receives
TYPEand reassignscontext.baz, the child machine will also update itsbazcontext?
No, this doesn't make sense.
If you told me where your location was and that later changed, would I know? No, not unless you told me (and/or if I asked you, and then you told me).
This is how the Actor model works, and it reflects how things work in real life. For the child machine to get the updated context it needs to be _sent_ an event notifying it of the updated context.
Hope that helps!
@davidkpiano so the data prop works like an INIT_CONTEXT event?
Yes, you got it. See https://www.w3.org/TR/scxml/#param for more info as it pertains to SCXML.