Created
June 6, 2021 20:02
-
-
Save jinnkhan88/e7f78f5f073824cb6ad1e9da0759568e to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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