Xstate: Question About Communication

Created on 12 Feb 2019  路  3Comments  路  Source: davidkpiano/xstate

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.

question

All 3 comments

When the parent machine receives TYPE and reassigns context.baz, the child machine will also update its baz context?

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

laurentpierson picture laurentpierson  路  3Comments

hnordt picture hnordt  路  3Comments

bradwoods picture bradwoods  路  3Comments

carloslfu picture carloslfu  路  3Comments

3plusalpha picture 3plusalpha  路  3Comments