Skip to content

Instantly share code, notes, and snippets.

@christiannwamba
Created May 15, 2020 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christiannwamba/00e94f99eafca462d4a9f531f2ea9312 to your computer and use it in GitHub Desktop.
Save christiannwamba/00e94f99eafca462d4a9f531f2ea9312 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// DEMO: Call events in child machines
// NOTE: Child machine viz is not supported yet
const childMachine = Machine({
id: 'child',
initial: 'step1',
states: {
step1: {
on: { STEP: 'step2' },
},
step2: {
on: { STEP: 'step3' },
},
step3: {
type: 'final',
},
},
})
const parentMachine = Machine({
id: 'parent',
initial: 'idle',
states: {
idle: {
on: { ACTIVATE: 'active' },
},
active: {
// invoke another machine
invoke: {
id: 'child',
src: childMachine,
// fired when child reaches `final`
onDone: 'done'
},
on: {
// trigger an event in a child machine
STEP: {
actions: send('STEP')
}
}
},
done: {},
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment