Created
May 2, 2020 10:12
-
-
Save plugboy/0f4b4e1d441defa0fac5a3256fd122d9 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
// State Machine for Charting | |
const stateMachine = Machine( | |
{ | |
id: 'stateMachine', | |
initial: 'idle', | |
context: { | |
file: undefined, | |
svg: undefined, | |
error: undefined | |
}, | |
states: { | |
idle: { | |
on: { | |
click: { target: 'idle', actions: 'startFileDialog' }, | |
change: { target: 'filePicked', cond: 'isFileListNotEmpty', actions: 'saveFileContext' } | |
} | |
}, | |
filePicked: { | |
on: { | |
'': [ | |
{ target: 'readFile', cond: 'isSvgFile'}, | |
{ target: 'wrongFileType'} | |
] | |
} | |
}, | |
readFile: { | |
exit: 'resetFileChange', | |
invoke: { | |
id: 'readFile', | |
src: 'readFile', | |
onDone: [ | |
{ target: 'fileLoaded', cond: 'shouldSaveSvgContext', actions: 'saveSvgContext' }, | |
{ target: 'idle', cond: 'isSvgContextUndefined' }, | |
{ target: 'fileLoaded'}, | |
], | |
onError: { target: 'loadFailed', actions: 'saveErrorContext' }, | |
} | |
}, | |
wrongFileType: { | |
entry: 'showFileTypeAlert', | |
exit: 'resetFileChange', | |
on: { | |
'': [ | |
{ target: 'idle', cond: 'isSvgContextUndefined' }, | |
{ target: 'fileLoaded'}, | |
] | |
} | |
}, | |
fileLoaded: { | |
on: { | |
click: { target: 'fileLoaded', actions: 'startFileDialog' }, | |
change: { target: 'filePicked', cond: 'isFileListNotEmpty', actions: 'saveFileContext' } | |
} | |
}, | |
loadFailed: { | |
on: { | |
'': 'idle' | |
} | |
} | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment