Skip to content

Instantly share code, notes, and snippets.

@pipex
Last active June 19, 2020 17:15
Show Gist options
  • Save pipex/dc355bee0b368a5fc80e62141db4996d to your computer and use it in GitHub Desktop.
Save pipex/dc355bee0b368a5fc80e62141db4996d to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const pong = Machine({
id: 'pong',
initial: 'started',
states: {
started: {
on: {
ping: { actions: sendParent('pong', { delay: 1000}) },
},
},
},
});
const ping = Machine({
id: 'ping',
initial: 'idle',
context: {
pong: null,
},
states: {
idle: {
on: {
start: {
target: 'ready',
actions: assign({
pong: () => spawn(pong),
}),
},
},
},
ready: {
on: {
ping: {
target: 'pinging',
actions: send('ping', { to: (ctx) => ctx.pong }),
},
},
},
pinging: {
on: {
pong: 'ready',
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment