Skip to content

Instantly share code, notes, and snippets.

@leighhalliday
Last active September 2, 2019 21:27
Show Gist options
  • Save leighhalliday/682a0d2639cd755a8ccf6f1d71a870f4 to your computer and use it in GitHub Desktop.
Save leighhalliday/682a0d2639cd755a8ccf6f1d71a870f4 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const videoMachine = Machine({
id: "video",
initial: "loading",
context: {
video: null,
duration: 0,
elapsed: 0
},
states: {
loading: {
on: {
LOADED: {
target: "ready",
actions: ["setVideo"]
},
FAIL: "failure"
}
},
ready: {
initial: "paused",
states: {
paused: {
on: {
PLAY: {
target: "playing",
actions: ["setElapsed", "playVideo"]
}
}
},
playing: {
on: {
TIMING: {
target: "playing",
actions: "setElapsed"
},
PAUSE: {
target: "paused",
actions: ["setElapsed", "pauseVideo"]
},
END: "ended"
}
},
ended: {
on: {
PLAY: {
target: "playing",
actions: "restartVideo"
}
}
}
}
},
failure: {
type: "final"
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment