Skip to content

Instantly share code, notes, and snippets.

@christiannwamba
Last active May 15, 2020 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christiannwamba/6ee36489a5e3b6dc238c6a5f957786d0 to your computer and use it in GitHub Desktop.
Save christiannwamba/6ee36489a5e3b6dc238c6a5f957786d0 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// DEMO: Call events anywhere (including parent machines/states) with callbacks
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