Skip to content

Instantly share code, notes, and snippets.

@jemgold
Created November 15, 2019 19:32
Show Gist options
  • Save jemgold/9982c50836e3a8789e9cf7de08174ddc to your computer and use it in GitHub Desktop.
Save jemgold/9982c50836e3a8789e9cf7de08174ddc to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const videoUri = 'foo';
const createReviewMachine = new Machine({
id: 'review',
type: 'parallel',
context: {
video: null,
videoUri,
duration: 0,
elapsed: 0,
uploadProgress: {
value: null,
max: null,
},
},
states: {
playback: {
initial: 'loading',
states: {
loading: {
on: {
LOADED: {
target: 'ready',
actions: ['setVideo'],
},
FAIL: 'failure',
}
},
ready: {
initial: 'playing',
states: {
playing: {
on: {
PAUSE: 'paused',
TIMING: {
target: 'playing',
actions: ['setElapsed'],
},
}
},
paused: {
on: {
PLAY: 'playing',
},
},
}
},
failure: {
type: 'final'
},
},
},
upload: {
initial: 'idle',
onDone: {
actions: 'uploadComplete',
},
states: {
idle: {
on: {
INIT_UPLOAD: {
target: 'pending',
},
},
},
pending: {
entry: () => {
console.log('pending')
},
invoke: {
src: 'uploadVideo',
},
on: {
UPLOAD_COMPLETE: 'success',
UPLOAD_PROGRESS: {
target: 'pending',
actions: ['setProgress']
}
}
},
success: {
type: 'final',
},
failure: {
// TODO: handle upload failures
},
},
},
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment