Last active
May 22, 2020 10:29
-
-
Save ronaiza-cardoso/52b3dbf52b6f8aa4b9ce94cce1dd89ef 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(({ 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