Created
November 5, 2020 20:25
-
-
Save cahnory/49cb3d793f24963ea970b38b03115470 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
Machine({ | |
id: 'JSON File', | |
initial: 'unknown', | |
context: { | |
path: null, | |
content: null, | |
}, | |
states: { | |
unknown: { | |
on: { | |
LOAD: 'reading', | |
}, | |
}, | |
notFound: { | |
on: { | |
LOAD: 'reading', | |
}, | |
}, | |
malformed: { | |
on: { | |
LOAD: 'reading', | |
}, | |
}, | |
resolved: { | |
on: { | |
LOAD: 'reading', | |
}, | |
}, | |
reading: { | |
invoke: { | |
id: 'readJSON', | |
src: async () => '{"foo":"bar"}', | |
onDone: 'parsing', | |
onError: { | |
target: 'notFound', | |
actions: assign({ | |
content: null, | |
}), | |
}, | |
}, | |
}, | |
parsing: { | |
invoke: { | |
id: 'parseJSON', | |
src: async (_, { data }) => JSON.parse(data), | |
onDone: { | |
target: 'resolved', | |
actions: assign({ | |
content: (_, event) => event.data, | |
}), | |
}, | |
onError: { | |
target: 'malformed', | |
actions: assign({ | |
content: null, | |
}), | |
}, | |
}, | |
}, | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment