Created
December 20, 2019 20:29
-
-
Save vitor-mariano/a4e039f275f29527b1d32331d0060d37 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
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