Last active
January 19, 2021 09:21
-
-
Save oknoorap/b669337f3667289654a3dc622ab36b6e 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 pawn = Machine({ | |
id: 'pawn', | |
context: { | |
notation: 'p' | |
} | |
}); | |
// const pieces = [pawn]; | |
const setupBoard = async (context, event) => { | |
context.board.push('abc') | |
console.log('setup board'); | |
return true; | |
} | |
const startTimer = (context, event) => { | |
console.log(context); | |
}; | |
const validMove = (context, event) => true; | |
const setupState = Machine({ | |
id: 'setupa', | |
invoke: { | |
id: 'board-setup', | |
src: 'setupBoard', | |
onDone: { | |
target: 'playing', | |
} | |
}, | |
entry: assign({ | |
pawnRef: () => spawn(pawn) | |
}) | |
}); | |
const playingState = Machine({ | |
id: 'playing', | |
initial: 'idle', | |
states: { | |
idle: { | |
entry: ['startTimer'] | |
} | |
} | |
}); | |
const loar = Machine({ | |
id: 'loar-machine', | |
initial: 'setup', | |
context: { | |
startTime: Date.now(), | |
turn: { | |
current: 'w', | |
white: { | |
time: 0, | |
move: 0 | |
}, | |
black: { | |
time: 0, | |
move: 0 | |
} | |
}, | |
notation: '', | |
captured: [], | |
castling: [], | |
board: [] | |
}, | |
states: { | |
setup: setupState, | |
playing: playingState | |
} | |
}, | |
{ | |
services: { | |
setupBoard | |
}, | |
actions: { | |
startTimer, | |
}, | |
guards: { | |
validMove | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment