Skip to content

Instantly share code, notes, and snippets.

@chukinas
Last active May 7, 2020 22:18
Show Gist options
  • Save chukinas/c9d533ec8e33f361facaf7c9af9b726c to your computer and use it in GitHub Desktop.
Save chukinas/c9d533ec8e33f361facaf7c9af9b726c to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const getActivePlayers = ctx => {
const players = ctx.status;
const activePlayers = players.filter(player=>{
player === 'active'
})
const activePlayerNames = Object.keys(activePlayers)
return activePlayerNames
}
const guards = {
isSelfEvent: ()=>false,
allDone: ()=>{
// Ignores disconnected players
return false
},
pendingSelf: ()=>{
// if Self is disconnected, return false
return false
},
}
const selfTest = Machine({
id: 'selfTest',
initial: 'unknown',
context: {
self: 'player1',
clues: {
player1: undefined,
player2: undefined,
player3: undefined,
},
status: {
player1: 'active',
player2: 'active',
player3: 'inactive',
},
},
states: {
unknown: {
on: {
'': [
{
target: 'done',
cond: 'allDone',
},
{
target: 'pendingSelf',
cond: 'pendingSelf',
},
{
target: 'pendingOthers',
target: 'pendingOthers',
},
],
},
},
done: {
type: 'final',
},
pendingSelf: {},
pendingOthers: {},
},
on: {
SUBMIT: {
target: '#selfTest',
actions: 'addClue',
},
WITHDRAW: {
target: '#selfTest',
actions: 'deleteClue',
},
DISCONNECT: {
target: '#selfTest',
actions: 'markDisconnected',
}
}
},
{
guards,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment