Last active
November 5, 2020 21:33
-
-
Save cahnory/92dbf12508e2991e0d34d8385412c851 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const fetchMachine = Machine({ | |
id: 'File', | |
initial: 'unknown', | |
context: { | |
path: '', | |
encoding: 'utf-8', | |
content: '', | |
parse: JSON.parse, | |
}, | |
states: { | |
unknown: { | |
on: { | |
READ: 'reading', | |
}, | |
}, | |
notFound: { | |
on: { | |
READ: 'reading', | |
}, | |
}, | |
malformed: { | |
on: { | |
READ: 'reading', | |
}, | |
}, | |
resolved: { | |
on: { | |
READ: 'reading', | |
}, | |
}, | |
reading: { | |
invoke: { | |
id: 'readJSON', | |
src: async (ctx) => '{"foo":"bar"}', | |
onDone: { | |
target: 'parsing', | |
actions: assign({ | |
content: (_, { data }) => data, | |
}), | |
}, | |
onError: { | |
target: 'notFound', | |
actions: assign({ | |
content: '', | |
}), | |
}, | |
}, | |
}, | |
parsing: { | |
invoke: { | |
id: 'parseJSON', | |
src: async ({ content, parse }) => parse(content), | |
onDone: { | |
target: 'resolved', | |
actions: assign({ | |
content: (_, event) => event.data, | |
}), | |
}, | |
onError: { | |
target: 'malformed', | |
actions: assign({ | |
content: '', | |
}), | |
}, | |
}, | |
}, | |
}, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment