Skip to content

Instantly share code, notes, and snippets.

@QMaximillian
Last active May 5, 2020 22:36
Show Gist options
  • Save QMaximillian/6f00cf3db8e61435cbb9e4bc4dc0b428 to your computer and use it in GitHub Desktop.
Save QMaximillian/6f00cf3db8e61435cbb9e4bc4dc0b428 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const soundMachine = Machine({
id: 'soundMachine',
initial: 'choose',
states: {
choose: {
on: {
PLAY_RED: {
actions: (context, event) => console.log(context, events)
}
}
}
}
}, {
actions: {
playRedSound: () => console.log('PLAYING RED SOUND')
}
})
const gameMachine = Machine({
id: 'gameMachine',
initial: 'gameOff',
context: {
levelSequence: [1, 2, 3, 4],
gameDispatchSequence: []
},
states: {
gameOn: {
id: 'gameOn',
states: {
watchMode: {
entry: ['createWatchModePattern'],
invoke: {
id: 'soundMachine',
src: 'soundMachine'
},
on: {
PLAY_RED: {
actions: send('PLAY_RED', { to: 'soundMachine'
})
}
}
},
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