Skip to content

Instantly share code, notes, and snippets.

@hosmelq
Last active March 12, 2020 05:31
Show Gist options
  • Save hosmelq/22b32cc95fc9626410b4198d6641a4f5 to your computer and use it in GitHub Desktop.
Save hosmelq/22b32cc95fc9626410b4198d6641a4f5 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
Machine(
{
id: `order-stop-machine`,
initial: `unknown`,
context: {
pictureUri: null,
signatureUri: null,
stop: null
},
states: {
unknown: {
on: {
'': [
{
cond: `isCompleted`,
target: `completed`
},
{
target: `pending`
}
]
}
},
completed: {
type: `final`
},
pending: {
initial: `idle`,
onDone: `completed`,
states: {
idle: {
on: {
COMPLETE: `completing`,
SIGN: `sign`,
TAKE_PICTURE: `picture`
}
},
picture: {
onDone: `idle`,
initial: `taking`,
states: {
taking: {
invoke: {
id: `takePicture`,
src: `takePicture`,
onDone: [
{
cond: `takePictureCancelled`,
target: `done`
},
{
target: `manipulate`
}
]
}
},
manipulate: {
invoke: {
id: `manipulateImage`,
src: `manipulateImage`,
onDone: {
actions: `setPictureUri`,
target: `done`
}
}
},
done: {
type: `final`
}
}
},
sign: {
initial: `idle`,
onDone: `idle`,
states: {
idle: {
entry: `lockScreenOrientation`,
on: {
CANCEL: `finished`,
DONE: `taking`
}
},
taking: {
invoke: {
id: `takeSignSnapshot`,
src: `takeSignSnapshot`,
onError: {
actions: `unlockScreenOrientation`,
target: `idle`
},
onDone: {
actions: `setSignatureUri`,
target: `finished`
}
}
},
finished: {
entry: `unlockScreenOrientation`,
type: `final`
}
}
},
completing: {
invoke: {
id: `completeStop`,
src: `completeStop`,
onDone: `success`
}
},
success: {
type: `final`
}
}
}
}
},
{
actions: {
setPictureUri: assign({
pictureUri: null
}),
setSignatureUri: assign({
signUri: null
}),
},
guards: {
isCompleted: ctx => false,
takePictureCancelled: (ctx, e) => false
}
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment