Skip to content

Instantly share code, notes, and snippets.

@jschloer
Created May 8, 2020 13:04
Show Gist options
  • Save jschloer/0b61383848e8fe83958b233185980155 to your computer and use it in GitHub Desktop.
Save jschloer/0b61383848e8fe83958b233185980155 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const secretMachine = Machine({
id: 'secret',
initial: 'wait',
context: {
secret: '42'
},
states: {
wait: {
after: {
1000: 'reveal'
}
},
reveal: {
type: 'final',
data: {
secret: (context, event) => context.secret
}
}
}
});
const parentMachine = Machine({
id: 'parent',
initial: 'pending',
context: {
revealedSecret: undefined
},
states: {
pending: {
invoke: {
id: 'secret',
src: secretMachine,
onDone: {
target: 'success',
actions: assign({
revealedSecret: (context, event) => {
// event is:
// { type: 'done.invoke.secret', data: { secret: '42' } }
return event.data.secret;
}
})
}
}
},
success: {
type: 'final'
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment