Last active
March 13, 2020 08:38
-
-
Save massimoselvi/38820a063e0af300a203a6960a452a1a 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
/* | |
Lambda Sequencer | |
preview: https://xstate.js.org/viz/?gist=31505a4986fab5d82190d55eec826648 | |
*/ | |
const machine = Machine({ | |
id: 'handler', | |
initial: 'idle', | |
states: { | |
idle: { | |
type: 'atomic', | |
on: { | |
LIST: 'processList', | |
// ITEM: 'processList.processItem', | |
// INVOKE: 'processList', | |
}, | |
}, | |
processList: { | |
// type: 'compound', | |
initial: 'looping', | |
states: { | |
looping: { | |
on: { | |
FETCH_NEXT_ITEM: 'processItem', | |
DONE: 'success', | |
}, | |
}, | |
processItem: { | |
id: 'processItem', | |
initial: 'NOT_PROCESSED', | |
context: { | |
failedAttempts: 0, | |
inputErrors: [], | |
systemErrors: [], | |
}, | |
states: { | |
NOT_PROCESSED: { | |
on: { | |
processList: { | |
target: 'PROCESSING', | |
actions: { | |
type: 'xstate.assign', | |
assignment: { | |
inputErrors: [], | |
}, | |
}, | |
}, | |
processItem: { | |
target: 'PROCESSING', | |
actions: { | |
type: 'xstate.assign', | |
assignment: { | |
inputErrors: [], | |
}, | |
}, | |
}, | |
}, | |
}, | |
PROCESSING: { | |
states: { | |
fetch: { | |
id: 'fetch', | |
initial: 'idle', | |
context: { | |
retries: 0, | |
}, | |
states: { | |
idle: { | |
on: { | |
FETCH: 'loading', | |
}, | |
}, | |
loading: { | |
on: { | |
RESOLVE: 'success', | |
REJECT: 'failure', | |
}, | |
}, | |
success: { | |
type: 'final', | |
}, | |
failure: { | |
on: { | |
RETRY: { | |
target: 'loading', | |
actions: assign({ | |
retries: (context, event) => context.retries + 1, | |
}), | |
}, | |
}, | |
}, | |
}, | |
}, | |
}, | |
on: { | |
succeed: { | |
target: 'PROCESSED', | |
actions: { | |
type: 'xstate.assign', | |
assignment: {}, | |
}, | |
}, | |
reject: { | |
target: 'NOT_PROCESSED', | |
actions: { | |
type: 'xstate.assign', | |
assignment: {}, | |
}, | |
}, | |
fail: { | |
target: 'PROCESS_ERRORED', | |
actions: { | |
type: 'xstate.assign', | |
assignment: {}, | |
}, | |
}, | |
}, | |
}, | |
PROCESS_ERRORED: { | |
on: { | |
retry: { | |
target: 'PROCESSING', | |
actions: { | |
type: 'xstate.assign', | |
assignment: { | |
systemErrors: [], | |
}, | |
}, | |
}, | |
}, | |
}, | |
PROCESSED: { | |
on: { | |
refresh: { | |
target: 'PROCESSING', | |
actions: { | |
type: 'xstate.assign', | |
assignment: { | |
failedAttempts: 0, | |
}, | |
}, | |
}, | |
}, | |
}, | |
}, | |
onDone: 'looping', | |
}, | |
success: { | |
type: 'final', | |
}, | |
// done: {}, | |
}, | |
onDone: 'idle', | |
}, | |
// pending: { | |
// type: 'parallel', | |
// states: { | |
// resource1: { | |
// type: 'compound', | |
// initial: 'pending', | |
// states: { | |
// pending: { | |
// on: { | |
// 'FULFILL.resource1': 'success', | |
// }, | |
// }, | |
// success: { | |
// type: 'final', | |
// }, | |
// }, | |
// }, | |
// resource2: { | |
// type: 'compound', | |
// initial: 'pending', | |
// states: { | |
// pending: { | |
// on: { | |
// 'FULFILL.resource2': 'success', | |
// }, | |
// }, | |
// success: { | |
// type: 'final', | |
// }, | |
// }, | |
// }, | |
// }, | |
// onDone: 'processList', | |
// }, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment