Skip to content

Instantly share code, notes, and snippets.

@cahnory
Created November 5, 2020 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cahnory/49cb3d793f24963ea970b38b03115470 to your computer and use it in GitHub Desktop.
Save cahnory/49cb3d793f24963ea970b38b03115470 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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