Skip to content

Instantly share code, notes, and snippets.

@LinusBorg
Last active Jul 10, 2020
Embed
What would you like to do?
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine({
id: 'uploader',
initial: 'idle',
context: {
retries: 0
},
on: {
RESET: {
target: 'idle',
actions: ['resetContext']
},
},
states: {
idle: {
entry: ['resetInputAndData'],
on: {
PARSE: 'parsing'
},
},
parsing: {
initial: 'processing',
states: {
processing: {
invoke: {
id: 'uploadProcessor',
src: 'uploadProcessor',
onDone: {
target: '#uploader.parsed',
actions: ['persistParsedCSVData'],
},
onError: {
target: 'error',
actions: ['setParseErrorMessage']
}
}
},
error: {
},
},
},
parsed: {
on: {
RESET: 'idle',
EXTRACT: 'extraction',
}
},
extraction: {
initial: 'searching',
states: {
searching: {
invoke: {
id: 'searchDataetStart',
src: 'searchDataetStart',
onDone: {
target: 'extracting',
actions: ['saveDatasetStart'],
},
onError: {
target: 'searchError',
actions: ['setSearchError']
}
}
},
searchError: {
},
extracting: {
invoke: {
id: 'searchDataetStart',
src: 'extractData',
onDone: {
target: 'extracted',
actions: ['saveData'],
},
onError: {
target: 'extractError',
actions: ['setExtractError']
}
}
},
extractError: {},
extracted: {
},
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment