Skip to content

Instantly share code, notes, and snippets.

@mirzap
Created December 9, 2020 14:18
Show Gist options
  • Save mirzap/6ba7fa9458851941a972d577cf74690c to your computer and use it in GitHub Desktop.
Save mirzap/6ba7fa9458851941a972d577cf74690c to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const timerMachine = Machine({
id: "timer",
initial: "pending",
states: {
pending: {
onEntry: ["setDefaults"],
on: {
START: "running"
}
},
running: {
invoke: {
id: "incInterval",
src: "startIntervalService"
},
onEntry: ["setNow", "startTimer"],
onExit: [
"setNow",
"stopTimer",
"updateLastElapsed",
"updateElapsedAndRemainingFromStopped"
],
on: {
PAUSE: "paused",
STOP: "stopped",
LAP: {
actions: [
"setNow",
"stopTimer",
"updateLastElapsed",
"updateElapsedAndRemainingFromStopped",
"startTimer"
]
},
RESET: {
target: "pending",
actions: "resetTimer"
},
UPDATE: {
actions: [
"setNow",
"updateElapsedFromRunning",
"updateRemainingFromRunning"
]
}
}
},
paused: {
on: {
RESUME: "running",
STOP: "stopped",
RESET: {
target: "pending",
actions: "resetTimer"
}
}
},
stopped: {
onEntry: "setFinal",
on: {
RESET: {
target: "pending",
actions: "resetTimer"
}
}
},
done: {
type: "final"
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment