// 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', }, }, });