Skip to content

Instantly share code, notes, and snippets.

@lucasmotta
Last active April 16, 2020 15:53
Show Gist options
  • Save lucasmotta/9155bf12696327ce31b4538187bddf3b to your computer and use it in GitHub Desktop.
Save lucasmotta/9155bf12696327ce31b4538187bddf3b 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: undefined,
duration: 0,
elapsed: 0,
},
states: {
loading: {
on: {
LOADED: {
target: 'ready',
actions: 'setVideo',
},
FAIL: 'failure',
},
},
ready: {
initial: 'paused',
states: {
history: {
type: 'history',
},
paused: {
on: {
PLAY: 'playing',
SHOW_SYNOPSIS: '#video.synopsis',
},
},
playing: {
initial: 'active',
on: {
TIMING: {
actions: 'setElapsed',
},
PAUSE: {
target: 'paused',
},
SHOW_SYNOPSIS: '#video.synopsis',
END: 'ended',
TOUCH_SCREEN: 'playing.active',
},
states: {
active: {
after: {
3000: 'idle',
},
},
idle: {},
},
},
ended: {
on: {
PLAY: {
target: 'playing',
actions: 'restartVideo',
},
},
},
},
},
synopsis: {
on: {
HIDE_SYNOPSIS: '#video.ready.history',
},
},
failure: {
type: 'final',
},
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment