Skip to content

Instantly share code, notes, and snippets.

@mwidmann
Created March 9, 2020 09:23
Show Gist options
  • Save mwidmann/6ccc5d3cacabe52a2c3c38aee8afb0f6 to your computer and use it in GitHub Desktop.
Save mwidmann/6ccc5d3cacabe52a2c3c38aee8afb0f6 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine({
key: 'video',
initial: 'loading',
context: {
video: document.createElement('video'),
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