Skip to content

Instantly share code, notes, and snippets.

@andreabadesso
Created April 8, 2021 19:21
Show Gist options
  • Save andreabadesso/7299c0ed0ce189bc121a06dce1e11638 to your computer and use it in GitHub Desktop.
Save andreabadesso/7299c0ed0ce189bc121a06dce1e11638 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const syncHandler = () => () => {
return () => {};
}
const SyncMachine = Machine({
id: 'sync',
initial: 'idle',
context: {
hasMoreBlocks: false,
},
states: {
idle: {
always: [
{ target: 'syncing', cond: 'hasMoreBlocks' },
],
on: { NEW_BLOCK: 'syncing' },
},
syncing: {
invoke: {
id: 'syncToLatestBlock',
src: 'syncHandler',
},
on: {
NEW_BLOCK: {
actions: ['setMoreBlocks'],
},
STOP: 'idle',
DONE: 'idle',
ERROR: 'failure',
},
entry: [
'resetMoreBlocks',
send('START', {
to: 'syncToLatestBlock',
}),
],
},
failure: {
type: 'final',
},
}
}, {
guards: {
hasMoreBlocks: (ctx) => ctx.hasMoreBlocks,
},
actions: {
resetMoreBlocks: assign({
hasMoreBlocks: () => false,
}),
setMoreBlocks: assign({
hasMoreBlocks: () => true,
}),
},
services: {
syncHandler,
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment