Skip to content

Instantly share code, notes, and snippets.

@ronaiza-cardoso
Last active May 22, 2020 10:29
Show Gist options
  • Save ronaiza-cardoso/52b3dbf52b6f8aa4b9ce94cce1dd89ef to your computer and use it in GitHub Desktop.
Save ronaiza-cardoso/52b3dbf52b6f8aa4b9ce94cce1dd89ef 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(({ type }) => {
if(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