Last active
November 16, 2020 19:58
-
-
Save MoonTahoe/cfb9f7977be5821edc33c9fde4058fe6 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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 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