Skip to content

Instantly share code, notes, and snippets.

@QMaximillian
Created May 6, 2020 02:21
Show Gist options
  • Save QMaximillian/ceb9b0eea0466af6b8986cedcbd374c3 to your computer and use it in GitHub Desktop.
Save QMaximillian/ceb9b0eea0466af6b8986cedcbd374c3 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const soundMachine = Machine({
id: 'sound',
initial: 'playRed',
states: {
playRed: {
entry: ['playRedSound']
},
}
}, {
actions: {
playRedSound: () => console.log('PLAYING RED SOUND')
}
})
const gameContainerMachine = Machine({
id: 'gameMachine',
initial: 'gameOff',
context: {
levelSequence: [1, 2, 3, 4],
gameDispatchSequence: []
},
states: {
gameOn: {
id: 'gameOn',
states: {
watchMode: {
entry: ['createWatchModePattern'],
invoke: {
id: 'sound',
src: soundMachine,
},
on: {
PLAY_RED: {
actions: send('PLAY_RED', { to: 'sound'
})
}
}
},
playMode: {
on: {
incorrect: {target: '#gameMachine.gameOver'}
}
},
}
},
gameOff: {
on: {
WATCH_MODE: '#gameOn.watchMode'
}
},
gameOver: {
on: {
RESTART_GAME: '#gameOn.watchMode'
}
}
}
}, {
actions: {
createWatchModePattern: assign({
gameDispatchSequence: (context, event) => context.levelSequence
}),
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment