Created
March 25, 2021 21:16
-
-
Save K3TH3R/8e2b88fbbd7854d36fa648db2b893dff to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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 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