Created
March 9, 2020 09:23
-
-
Save mwidmann/6ccc5d3cacabe52a2c3c38aee8afb0f6 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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