Skip to content

Instantly share code, notes, and snippets.

@K3TH3R
Created March 25, 2021 21:16
Show Gist options
  • Save K3TH3R/8e2b88fbbd7854d36fa648db2b893dff to your computer and use it in GitHub Desktop.
Save K3TH3R/8e2b88fbbd7854d36fa648db2b893dff to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const drawingStateMachineDef = Machine({
id: 'appDrawing',
initial: 'inactive',
states: {
inactive: {
on: {
START_DRAW: 'drawing',
}
},
drawing: {
on: {
CANCEL: 'cleanReset',
FINISH: {
target: 'showAnnotationCard',
actions: ['showAnnotationCard'],
},
ADD_POINT: {
actions: ['addPoint'],
},
}
},
showAnnotationCard: {
on: {
CLOSE: 'cleanReset',
SAVE: 'saving',
}
},
saving: {
invoke: {
id: 'saveDrawing',
src: (ctx, event) => fetch(`url/to/save/drawing`).then(r => r.json()),
onDone: {
target: 'showAnnotationCard',
},
onError: {
target: 'showAnnotationCard',
}
}
},
cleanReset: {
always: [
{
target: 'inactive',
actions: ['removeDrawing', 'resetTool'],
}
],
},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment