Skip to content

Instantly share code, notes, and snippets.

@oknoorap
Last active January 19, 2021 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oknoorap/b669337f3667289654a3dc622ab36b6e to your computer and use it in GitHub Desktop.
Save oknoorap/b669337f3667289654a3dc622ab36b6e to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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