Last active
June 19, 2020 17:15
-
-
Save pipex/dc355bee0b368a5fc80e62141db4996d to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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 pong = Machine({ | |
id: 'pong', | |
initial: 'started', | |
states: { | |
started: { | |
on: { | |
ping: { actions: sendParent('pong', { delay: 1000}) }, | |
}, | |
}, | |
}, | |
}); | |
const ping = Machine({ | |
id: 'ping', | |
initial: 'idle', | |
context: { | |
pong: null, | |
}, | |
states: { | |
idle: { | |
on: { | |
start: { | |
target: 'ready', | |
actions: assign({ | |
pong: () => spawn(pong), | |
}), | |
}, | |
}, | |
}, | |
ready: { | |
on: { | |
ping: { | |
target: 'pinging', | |
actions: send('ping', { to: (ctx) => ctx.pong }), | |
}, | |
}, | |
}, | |
pinging: { | |
on: { | |
pong: 'ready', | |
}, | |
}, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment