Created
November 15, 2019 19:34
-
-
Save jemgold/1c927326a6a2d9d2e42b27965492ea1e 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 cameraMachine = new Machine({ | |
id: 'camera', | |
initial: 'requestPermissions', | |
context: { | |
camera: null, | |
videoUri: null, | |
}, | |
states: { | |
requestPermissions: { | |
initial: 'pending', | |
states: { | |
pending: { | |
invoke: { | |
id: 'requestPermissions', | |
onDone: { | |
target: '#camera.capture' | |
}, | |
onError: { | |
target: 'failure', | |
}, | |
// src: | |
}, | |
}, | |
failure: {}, | |
} | |
}, | |
capture: { | |
initial: 'loading', | |
states: { | |
loading: { | |
on: { | |
CAMERA_READY: { | |
target: 'ready.idle', | |
actions: 'setCamera', | |
} | |
} | |
}, | |
ready: { | |
states: { | |
idle: { | |
on: { | |
PRESS_RECORD: 'active', | |
} | |
}, | |
active: { | |
invoke: { | |
id: 'recordVideo', | |
src: (context, event) => { | |
// fake camera recording | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve({ uri: 'yo' }) | |
}, 1000) | |
}) | |
}, | |
onDone: { | |
target: '#camera.review', | |
actions: assign({ | |
videoUri: (context, event) => { | |
return event.data.uri; | |
}, | |
}), | |
// cond: (context, event) => { | |
// return event.data.uri !== null, | |
// } | |
}, | |
onError: { | |
target: '#camera.capture.failure', | |
actions: (context, event) => { | |
console.log(event) | |
}, | |
} | |
}, | |
on: { | |
FINISH_RECORD: { | |
actions: (context, event) => { | |
console.log('stop recording') | |
}, | |
}, | |
}, | |
}, | |
}, | |
}, | |
failure: {}, | |
}, | |
on: { | |
FAIL: '.failure', | |
} | |
}, | |
review: { | |
on: { | |
DISMISS: 'capture', | |
SENT: { | |
actions: () => { | |
console.log('upload complete') | |
} | |
} | |
} | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment