Last active
September 11, 2021 06:54
-
-
Save JayBee007/422e0625c0d8b0a5cda75581dda7b3d3 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 timerMachine = Machine({ | |
id: 'timerMachine', | |
initial: "paused", | |
states: { | |
paused: { | |
on: { | |
START: { | |
target: 'running' | |
} | |
} | |
}, | |
running: { | |
initial: 'round', | |
invoke: { | |
src: () => (cb) => { | |
let timerId = setInterval(() => { | |
cb('TICK') | |
}, 1000) | |
return () => clearInterval(timerId) | |
}, | |
}, | |
on: { | |
TICK: { | |
actions: assign({ | |
secondsLeft: (ctx) => ctx.secondsLeft - 1 | |
}) | |
} | |
}, | |
states: { | |
round: { | |
on: { | |
'': { | |
target: 'interval', | |
cond: (ctx) => ctx.secondsLeft < 0 | |
} | |
} | |
}, | |
interval: {} | |
}, | |
on: { | |
PAUSED: { | |
target: 'paused' | |
} | |
} | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment