Skip to content

Instantly share code, notes, and snippets.

@jinnkhan88
Created June 6, 2021 20:02
Show Gist options
  • Save jinnkhan88/e7f78f5f073824cb6ad1e9da0759568e to your computer and use it in GitHub Desktop.
Save jinnkhan88/e7f78f5f073824cb6ad1e9da0759568e to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const echoCallbackHandler = (context, event) => (callback, onEvent) => {
onEvent(e => {
if (e.type === 'HEAR') {
callback('ECHO')
}
})
}
const echoMachine = Machine({
id: 'echo',
initial: 'listening',
states: {
listening: {
invoke: {
id: 'echoCallback',
src: echoCallbackHandler,
},
on: {
SPEAK: {
actions: send('HEAR', { to: 'echoCallback' }),
},
ECHO: {
actions: () => {
console.log('echo, echo')
},
},
},
},
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment