Skip to content

Instantly share code, notes, and snippets.

@MoonTahoe
Last active November 16, 2020 19:58
Show Gist options
  • Save MoonTahoe/cfb9f7977be5821edc33c9fde4058fe6 to your computer and use it in GitHub Desktop.
Save MoonTahoe/cfb9f7977be5821edc33c9fde4058fe6 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'timer',
initial: 'idle',
context: {
index: 0
},
states: {
idle: {
on: {
START: 'recording'
}
},
recording: {
on: {
NEXT: {
target: 'recording',
actions: ['moveNext']
},
PREV: {
target: 'recording',
actions: ['movePrev']
},
END: {
target: 'finished',
actions: ['doMath']
}
}
},
finished: {
on: {
DONE: 'idle'
}
}
}
}, {
actions: {
moveNext: ({ index }, events) => {
assign({
index: index + 1
})
},
movePrev: (context, events) => {
assign({
index: index - 1
})
},
doMath: (context, events) => {
alert('do math: ' + context.index)
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment