Skip to content

Instantly share code, notes, and snippets.

@pipex
Last active September 1, 2020 19:45
Show Gist options
  • Save pipex/514ade5c3e4d56835943fdf5e7d30bf4 to your computer and use it in GitHub Desktop.
Save pipex/514ade5c3e4d56835943fdf5e7d30bf4 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const ponger = Machine({
id: 'ponger',
initial: 'ready',
context: {
pongs: 0,
},
states: {
ready: {
on: {
PING: {
actions: [
assign({pongs: (c) => c.pongs + 1}),
sendParent('PONG', {delay: 2000})
]
}
}
}
}
});
const pinger = Machine({
id: 'pinger',
initial: 'stopped',
context: {
pings: 0
},
states: {
stopped: {
on: {
START: {
target: 'ready',
actions: assign({
ponger: (_) => spawn(ponger)
})
}
}
},
ready: {
after: {
2000: 'pinging'
},
on: {
PING: 'pinging'
}
},
pinging: {
entry: [
assign({pings: (c) => c.pings + 1}),
send('PING', {to: (c) => c.ponger})],
on: {
PONG: {
target: 'ready',
}
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment