Skip to content

Instantly share code, notes, and snippets.

@lucasmotta
Created April 22, 2020 10:48
Show Gist options
  • Save lucasmotta/5f6e9aad1a6e198177e983c2acc91dc4 to your computer and use it in GitHub Desktop.
Save lucasmotta/5f6e9aad1a6e198177e983c2acc91dc4 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({
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: {
hist: {
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.hist',
},
},
failure: {
type: 'final',
},
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment