Skip to content

Instantly share code, notes, and snippets.

@vitor-mariano
Created December 20, 2019 20:29
Show Gist options
  • Save vitor-mariano/a4e039f275f29527b1d32331d0060d37 to your computer and use it in GitHub Desktop.
Save vitor-mariano/a4e039f275f29527b1d32331d0060d37 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,
elapsed: 0,
duration: 0,
},
states: {
loading: {
on: {
LOADED: {
target: 'ready',
actions: ['setVideo'],
},
FAILED: 'failure',
},
},
ready: {
initial: 'paused',
states: {
paused: {
on: {
PLAY: {
target: 'playing',
actions: ['playVideo'],
},
},
},
playing: {
on: {
PAUSE: {
target: 'paused',
actions: ['pauseVideo'],
},
TIMING: {
target: 'playing',
actions: ['setElapsed'],
},
END: 'ended',
},
},
ended: {
on: {
RESTART: {
target: 'playing',
actions: ['playVideo'],
},
},
},
},
},
failure: {
type: 'final',
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment